From ace9962a6fdff6ca895fc848aedef5e9f226c1af Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 30 Jul 2025 10:46:01 +0700 Subject: [PATCH 1/4] #1704 --- .../ProfileGovernmentController.ts | 66 ++++++++--------- .../ProfileGovernmentEmployeeController.ts | 72 +++++++++---------- 2 files changed, 69 insertions(+), 69 deletions(-) diff --git a/src/controllers/ProfileGovernmentController.ts b/src/controllers/ProfileGovernmentController.ts index 7e8c4e2a..6f63bd0e 100644 --- a/src/controllers/ProfileGovernmentController.ts +++ b/src/controllers/ProfileGovernmentController.ts @@ -213,7 +213,7 @@ export class ProfileGovernmentHistoryController extends Controller { }, }); - if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + // if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); const fullNameParts = [ posMaster == null || posMaster.orgChild4 == null ? null : posMaster.orgChild4.orgChild4Name, posMaster == null || posMaster.orgChild3 == null ? null : posMaster.orgChild3.orgChild3Name, @@ -248,31 +248,31 @@ export class ProfileGovernmentHistoryController extends Controller { } const orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); const data = { - org: record.isLeave == false ? org : orgLeave, //สังกัด + org: record?.isLeave == false ? org : orgLeave, //สังกัด positionField: position == null ? null : position.positionField, //สายงาน - position: record.position, //ตำแหน่ง - posLevel: record.posLevel == null ? null : record.posLevel.posLevelName, //ระดับ - posMasterNo: record.isLeave == false + position: record?.position, //ตำแหน่ง + posLevel: record?.posLevel == null ? null : record?.posLevel.posLevelName, //ระดับ + posMasterNo: record?.isLeave == false ? posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}` - : record.profileSalary.length > 0 - ? `${record.profileSalary[0].posNoAbb} ${record.profileSalary[0].posNo}` + : record && record?.profileSalary.length > 0 + ? `${record?.profileSalary[0].posNoAbb} ${record?.profileSalary[0].posNo}` : null, //เลขที่ตำแหน่ง - posType: record.posType == null ? null : record.posType.posTypeName, //ประเภท + posType: record?.posType == null ? null : record?.posType.posTypeName, //ประเภท posExecutive: position == null || position.posExecutive == null ? null : position.posExecutive.posExecutiveName, //ตำแหน่งทางการบริหาร positionArea: position == null ? null : position.positionArea, //ด้าน/สาขา positionExecutiveField: position == null ? null : position.positionExecutiveField, //ด้านทางการบริหาร - dateLeave: record.birthDate == null ? null : calculateRetireDate(record.birthDate), - dateRetireLaw: record.dateRetireLaw ?? null, - // govAge: record.dateStart == null ? null : calculateAge(record.dateStart), + dateLeave: record?.birthDate == null ? null : calculateRetireDate(record?.birthDate), + dateRetireLaw: record?.dateRetireLaw ?? null, + // govAge: record?.dateStart == null ? null : calculateAge(record?.dateStart), govAge: await calculateGovAge(profileId, "OFFICER"), - dateAppoint: record.dateAppoint, - dateStart: record.dateStart, - govAgeAbsent: record.govAgeAbsent, - govAgePlus: record.govAgePlus, - reasonSameDate: record.reasonSameDate, + dateAppoint: record?.dateAppoint, + dateStart: record?.dateStart, + govAgeAbsent: record?.govAgeAbsent, + govAgePlus: record?.govAgePlus, + reasonSameDate: record?.reasonSameDate, }; return new HttpSuccess(data); @@ -349,7 +349,7 @@ export class ProfileGovernmentHistoryController extends Controller { }, }); - if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + // if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); const fullNameParts = [ posMaster == null || posMaster.orgChild4 == null ? null : posMaster.orgChild4.orgChild4Name, posMaster == null || posMaster.orgChild3 == null ? null : posMaster.orgChild3.orgChild3Name, @@ -384,35 +384,35 @@ export class ProfileGovernmentHistoryController extends Controller { } const orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); const data = { - org: record.isLeave == false ? org : orgLeave, //สังกัด + org: record?.isLeave == false ? org : orgLeave, //สังกัด positionField: position == null ? null : position.positionField, //สายงาน - position: record.position, //ตำแหน่ง - posLevel: record.posLevel == null ? null : record.posLevel.posLevelName, //ระดับ + position: record?.position, //ตำแหน่ง + posLevel: record?.posLevel == null ? null : record?.posLevel.posLevelName, //ระดับ posMasterNo: - record.isLeave == false + record?.isLeave == false ? posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}` - : record?.profileSalary.length > 0 - ? `${record.profileSalary[0].posNoAbb} ${record.profileSalary[0].posNo}` + : record && record.profileSalary.length > 0 + ? `${record?.profileSalary[0].posNoAbb} ${record?.profileSalary[0].posNo}` : null, //เลขที่ตำแหน่ง - posType: record.posType == null ? null : record.posType.posTypeName, //ประเภท + posType: record?.posType == null ? null : record?.posType.posTypeName, //ประเภท posExecutive: position == null || position.posExecutive == null ? null : position.posExecutive.posExecutiveName, //ตำแหน่งทางการบริหาร positionArea: position == null ? null : position.positionArea, //ด้าน/สาขา positionExecutiveField: position == null ? null : position.positionExecutiveField, //ด้านทางการบริหาร - dateLeave: record.birthDate == null ? null : calculateRetireDate(record.birthDate), - dateRetireLaw: record.dateRetireLaw ?? null, - // govAge: record.dateStart == null ? null : calculateAge(record.dateStart), + dateLeave: record?.birthDate == null ? null : calculateRetireDate(record?.birthDate), + dateRetireLaw: record?.dateRetireLaw ?? null, + // govAge: record?.dateStart == null ? null : calculateAge(record?.dateStart), govAge: await calculateGovAge(profileId, "OFFICER"), - dateAppoint: record.dateAppoint, - dateStart: record.dateStart, - govAgeAbsent: record.govAgeAbsent, - govAgePlus: record.govAgePlus, - reasonSameDate: record.reasonSameDate, - isLeave: record.isLeave + dateAppoint: record?.dateAppoint, + dateStart: record?.dateStart, + govAgeAbsent: record?.govAgeAbsent, + govAgePlus: record?.govAgePlus, + reasonSameDate: record?.reasonSameDate, + isLeave: record?.isLeave }; return new HttpSuccess(data); diff --git a/src/controllers/ProfileGovernmentEmployeeController.ts b/src/controllers/ProfileGovernmentEmployeeController.ts index 32c32006..f93c96f0 100644 --- a/src/controllers/ProfileGovernmentEmployeeController.ts +++ b/src/controllers/ProfileGovernmentEmployeeController.ts @@ -192,7 +192,7 @@ export class ProfileGovernmentEmployeeController extends Controller { }, }); - if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + // if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); const fullNameParts = [ posMaster == null || posMaster.orgChild4 == null ? null : posMaster.orgChild4.orgChild4Name, posMaster == null || posMaster.orgChild3 == null ? null : posMaster.orgChild3.orgChild3Name, @@ -227,28 +227,28 @@ export class ProfileGovernmentEmployeeController extends Controller { } const orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); const data = { - org: record.isLeave == false ? org : orgLeave, //สังกัด - position: record.position, //ตำแหน่ง + org: record?.isLeave == false ? org : orgLeave, //สังกัด + position: record?.position, //ตำแหน่ง posLevel: - record.posLevel == null + record?.posLevel == null ? null : `${record?.posType?.posTypeShortName ?? ""} ${record?.posLevel?.posLevelName ?? ""}`, //ระดับ - posMasterNo: record.isLeave == false + posMasterNo: record?.isLeave == false ? posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}` - : record.profileSalary.length > 0 - ? `${record.profileSalary[0].posNoAbb} ${record.profileSalary[0].posNo}` + : record && record?.profileSalary.length > 0 + ? `${record?.profileSalary[0].posNoAbb} ${record?.profileSalary[0].posNo}` : null, //เลขที่ตำแหน่ง - posType: record.posType == null ? null : record.posType.posTypeName, //ประเภท - dateLeave: record.birthDate == null ? null : calculateRetireDate(record.birthDate), //วันเกษียณ - dateAppoint: record.dateAppoint, //วันที่สั่งบรรจุ - dateStart: record.dateStart, //วันที่เริ่มปฎิบัติงานราชการ - reasonSameDate: record.reasonSameDate, //เหตุผลที่วันที่ไม่ตรงกัน - dateRetire: record.dateRetire ?? null, //วันครบเกษียณอายุ - // govAge: record.dateStart == null ? null : calculateAge(record.dateStart), //อายุราชการ + posType: record?.posType == null ? null : record?.posType.posTypeName, //ประเภท + dateLeave: record?.birthDate == null ? null : calculateRetireDate(record?.birthDate), //วันเกษียณ + dateAppoint: record?.dateAppoint, //วันที่สั่งบรรจุ + dateStart: record?.dateStart, //วันที่เริ่มปฎิบัติงานราชการ + reasonSameDate: record?.reasonSameDate, //เหตุผลที่วันที่ไม่ตรงกัน + dateRetire: record?.dateRetire ?? null, //วันครบเกษียณอายุ + // govAge: record?.dateStart == null ? null : calculateAge(record?.dateStart), //อายุราชการ govAge: await calculateGovAge(profileEmployeeId, "EMPLOYEE"), - govAgeAbsent: record.govAgeAbsent ?? null, // ขาดราชการ - govAgePlus: record.govAgePlus, // อายุราชการเกื้อกูล - dateRetireLaw: record.dateRetireLaw ?? null, // วันที่เกษียฯอายุราชการตามกฎหมาย + govAgeAbsent: record?.govAgeAbsent ?? null, // ขาดราชการ + govAgePlus: record?.govAgePlus, // อายุราชการเกื้อกูล + dateRetireLaw: record?.dateRetireLaw ?? null, // วันที่เกษียฯอายุราชการตามกฎหมาย }; return new HttpSuccess(data); } @@ -305,7 +305,7 @@ export class ProfileGovernmentEmployeeController extends Controller { }, }); - if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + // if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); const fullNameParts = [ posMaster == null || posMaster.orgChild4 == null ? null : posMaster.orgChild4.orgChild4Name, posMaster == null || posMaster.orgChild3 == null ? null : posMaster.orgChild3.orgChild3Name, @@ -340,31 +340,31 @@ export class ProfileGovernmentEmployeeController extends Controller { } const orgLeave = _OrgLeave.filter((x:any) => x !== undefined && x !== null).join("\n"); const data = { - org: record.isLeave == false ? org : orgLeave, //สังกัด - position: record.position, //ตำแหน่ง - posLevel: record.posLevel == null && record.posType == null + org: record?.isLeave == false ? org : orgLeave, //สังกัด + position: record?.position, //ตำแหน่ง + posLevel: record?.posLevel == null && record?.posType == null ? null - : `${record.posType.posTypeShortName} ${record.posLevel.posLevelName}`, //ระดับ + : `${record?.posType.posTypeShortName} ${record?.posLevel.posLevelName}`, //ระดับ posMasterNo: - record.isLeave == false + record?.isLeave == false ? posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}` - : record?.profileSalary.length > 0 - ? `${record.profileSalary[0].posNoAbb} ${record.profileSalary[0].posNo}` + : record && record.profileSalary.length > 0 + ? `${record?.profileSalary[0].posNoAbb} ${record?.profileSalary[0].posNo}` : null, //เลขที่ตำแหน่ง - posType: record.posType == null ? null : record.posType.posTypeName, //ประเภท - dateLeave: record.birthDate == null ? null : calculateRetireDate(record.birthDate), //วันเกษียณ - dateAppoint: record.dateAppoint, //วันที่สั่งบรรจุ - dateStart: record.dateStart, //วันที่เริ่มปฎิบัติงานราชการ - reasonSameDate: record.reasonSameDate, //เหตุผลที่วันที่ไม่ตรงกัน - dateRetire: record.dateRetire ?? null, //วันครบเกษียณอายุ - // govAge: record.dateStart == null ? null : calculateAge(record.dateStart), //อายุราชการ + posType: record?.posType == null ? null : record?.posType.posTypeName, //ประเภท + dateLeave: record?.birthDate == null ? null : calculateRetireDate(record?.birthDate), //วันเกษียณ + dateAppoint: record?.dateAppoint, //วันที่สั่งบรรจุ + dateStart: record?.dateStart, //วันที่เริ่มปฎิบัติงานราชการ + reasonSameDate: record?.reasonSameDate, //เหตุผลที่วันที่ไม่ตรงกัน + dateRetire: record?.dateRetire ?? null, //วันครบเกษียณอายุ + // govAge: record?.dateStart == null ? null : calculateAge(record?.dateStart), //อายุราชการ govAge: await calculateGovAge(profileEmployeeId, "EMPLOYEE"), - govAgeAbsent: record.govAgeAbsent ?? null, // ขาดราชการ - govAgePlus: record.govAgePlus, // อายุราชการเกื้อกูล - dateRetireLaw: record.dateRetireLaw ?? null, // วันที่เกษียฯอายุราชการตามกฎหมาย - isLeave: record.isLeave + govAgeAbsent: record?.govAgeAbsent ?? null, // ขาดราชการ + govAgePlus: record?.govAgePlus, // อายุราชการเกื้อกูล + dateRetireLaw: record?.dateRetireLaw ?? null, // วันที่เกษียฯอายุราชการตามกฎหมาย + isLeave: record?.isLeave }; return new HttpSuccess(data); } From 0f89aa4a9235eff1c7284d5b33d8e6dfc72e55d7 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 30 Jul 2025 14:06:22 +0700 Subject: [PATCH 2/4] shortName --- src/controllers/ProfileController.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 151472c8..fd43d0b1 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -6151,12 +6151,16 @@ export class ProfileController extends Controller { "orgRoot.orgRootShortName", "orgRoot.orgRootOrder", "orgChild1.orgChild1Name", + "orgChild1.orgChild1ShortName", "orgChild1.orgChild1Order", "orgChild2.orgChild2Name", + "orgChild2.orgChild2ShortName", "orgChild2.orgChild2Order", "orgChild3.orgChild3Name", + "orgChild3.orgChild3ShortName", "orgChild3.orgChild3Order", "orgChild4.orgChild4Name", + "orgChild4.orgChild4ShortName", "orgChild4.orgChild4Order", ]) .where(node && nodeId ? "current_holders.orgRevisionId = :orgRevisionId" : "1=1", { @@ -6253,6 +6257,21 @@ export class ProfileController extends Controller { ] .filter(Boolean) .join("\n"); + + const shortName = + !holder + ? null + : holder.orgChild4 != null + ? `${holder.orgChild4.orgChild4ShortName} ${holder.posMasterNo}` + : holder.orgChild3 != null + ? `${holder.orgChild3.orgChild3ShortName} ${holder.posMasterNo}` + : holder.orgChild2 != null + ? `${holder.orgChild2.orgChild2ShortName} ${holder.posMasterNo}` + : holder.orgChild1 != null + ? `${holder.orgChild1.orgChild1ShortName} ${holder.posMasterNo}` + : holder.orgRoot != null + ? `${holder.orgRoot.orgRootShortName} ${holder.posMasterNo}` + : null; return { id: _data.id, @@ -6269,7 +6288,7 @@ export class ProfileController extends Controller { posLevelId: _data.posLevel?.id ?? null, posTypeId: _data.posType?.id ?? null, position: _data.position, - posNo: holder?.posMasterNo ?? null, + posNo: shortName ?? null, rootId: holder?.orgRoot?.id ?? null, root: holder?.orgRoot?.orgRootName ?? null, orgRootShortName: holder?.orgRoot?.orgRootShortName ?? null, From 900fb8deb5666f247e4824c071341242341389b2 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 30 Jul 2025 17:03:24 +0700 Subject: [PATCH 3/4] =?UTF-8?q?=E0=B8=84=E0=B9=89=E0=B8=99=E0=B8=AB?= =?UTF-8?q?=E0=B8=B2=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=8A=E0=B8=B7=E0=B9=88?= =?UTF-8?q?=E0=B8=AD=E0=B8=96=E0=B9=89=E0=B8=B2=E0=B9=84=E0=B8=A1=E0=B9=88?= =?UTF-8?q?=E0=B8=AA=E0=B9=88=E0=B8=87=20system=20=E0=B8=A1=E0=B8=B2?= =?UTF-8?q?=E0=B9=83=E0=B8=AB=E0=B9=89=20default=20=E0=B8=95=E0=B8=B2?= =?UTF-8?q?=E0=B8=A1=E0=B8=97=E0=B8=B0=E0=B9=80=E0=B8=9A=E0=B8=B5=E0=B8=A2?= =?UTF-8?q?=E0=B8=99=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=A7=E0=B8=B1=E0=B8=95?= =?UTF-8?q?=E0=B8=B4=20#1689?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 353 +++++++----------- src/controllers/ProfileEmployeeController.ts | 336 ++++++----------- .../ProfileEmployeeTempController.ts | 181 +++++---- 3 files changed, 342 insertions(+), 528 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index fd43d0b1..002cedc2 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -8264,237 +8264,150 @@ export class ProfileController extends Controller { */ @Post("search-personal") async getProfileBySearchKeyword( + @Request() request: RequestWithUser, @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Body() body: { fieldName?: string | null; keyword?: string; + system?: string; }, ) { - let findProfile: any; - let total: any; - let revision = await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true } }); - const skip = (page - 1) * pageSize; - const take = pageSize; - let queryLike = `CONCAT( - IFNULL(orgChild4.orgChild4ShortName, '')," ", - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgChild3.orgChild3ShortName, '')," ", - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgChild2.orgChild2ShortName, '')," ", - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgChild1.orgChild1ShortName, '')," ", - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgRoot.orgRootShortName, '')," ", - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword`; - - switch (body.fieldName) { - case "citizenId": - [findProfile, total] = await this.profileRepo.findAndCount({ - where: { - citizenId: Like(`%${body.keyword}%`), - current_holders: { - orgRevisionId: revision?.id, - }, - }, - relations: [ - "posType", - "posLevel", - "current_holders", - "current_holders.orgRoot", - "current_holders.orgChild1", - "current_holders.orgChild2", - "current_holders.orgChild3", - "current_holders.orgChild4", - ], - skip, - take, - }); - break; - - case "fullName": - [findProfile, total] = await this.profileRepo - .createQueryBuilder("profile") - .leftJoinAndSelect("profile.posType", "posType") - .leftJoinAndSelect("profile.posLevel", "posLevel") - .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") - .where("current_holders.orgRevision = :revisionId", { revisionId: revision?.id }) - .andWhere( - "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword", - { keyword: `%${body.keyword}%` }, - ) - .skip(skip) - .take(take) - .getManyAndCount(); - break; - - case "position": - [findProfile, total] = await this.profileRepo.findAndCount({ - where: { - position: Like(`%${body.keyword}%`), - current_holders: { - orgRevisionId: revision?.id, - }, - }, - relations: [ - "posType", - "posLevel", - "current_holders", - "current_holders.orgRoot", - "current_holders.orgChild1", - "current_holders.orgChild2", - "current_holders.orgChild3", - "current_holders.orgChild4", - ], - skip, - take, - }); - break; - - case "posNo": - [findProfile, total] = await this.profileRepo - .createQueryBuilder("profile") - .leftJoinAndSelect("profile.posType", "posType") - .leftJoinAndSelect("profile.posLevel", "posLevel") - .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") - .where("current_holders.orgRevision = :revisionId", { revisionId: revision?.id }) - .andWhere( - new Brackets((qb) => { - qb.orWhere( - body.keyword != undefined && body.keyword != null && body.keyword != "" - ? queryLike - : "1=1", - { - keyword: `%${body.keyword}%`, - }, - ); - }), - ) - .skip(skip) - .take(take) - .getManyAndCount(); - break; - - case "posType": - [findProfile, total] = await this.profileRepo.findAndCount({ - where: { - posType: { - posTypeName: Like(`%${body.keyword}%`), - }, - current_holders: { - orgRevisionId: revision?.id, - }, - }, - relations: [ - "posType", - "posLevel", - "current_holders", - "current_holders.orgRoot", - "current_holders.orgChild1", - "current_holders.orgChild2", - "current_holders.orgChild3", - "current_holders.orgChild4", - ], - skip, - take, - }); - break; - - case "posLevel": - [findProfile, total] = await this.profileRepo.findAndCount({ - where: { - posLevel: { - posLevelName: Like(`%${body.keyword}%`), - }, - current_holders: { - orgRevisionId: revision?.id, - }, - }, - relations: [ - "posType", - "posLevel", - "current_holders", - "current_holders.orgRoot", - "current_holders.orgChild1", - "current_holders.orgChild2", - "current_holders.orgChild3", - "current_holders.orgChild4", - ], - skip, - take, - }); - break; - - case "organization": - [findProfile, total] = await this.profileRepo.findAndCount({ - where: { - current_holders: { - orgRevisionId: revision?.id, - orgRoot: { - orgRootName: Like(`%${body.keyword}%`), - }, - }, - }, - relations: [ - "posType", - "posLevel", - "current_holders", - "current_holders.orgRoot", - "current_holders.orgChild1", - "current_holders.orgChild2", - "current_holders.orgChild3", - "current_holders.orgChild4", - ], - skip, - take, - }); - break; - - default: - [findProfile, total] = await this.profileRepo.findAndCount({ - where: { - current_holders: { - orgRevisionId: revision?.id, - }, - }, - relations: [ - "posType", - "posLevel", - "current_holders", - "current_holders.orgRoot", - "current_holders.orgChild1", - "current_holders.orgChild2", - "current_holders.orgChild3", - "current_holders.orgChild4", - ], - skip, - take, - }); - break; - } - - const findRevision = await this.orgRevisionRepo.findOne({ - where: { orgRevisionIsCurrent: true }, - }); + // ค้นหารายชื่อถ้าไม่ส่ง system มาให้ default ตามทะเบียนประวัติ + let _system:string ="SYS_REGISTRY_OFFICER"; + if(body.system) + _system = body.system; + let _data = await new permission().PermissionOrgList(request, _system); + const findRevision = await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true } }); if (!findRevision) { throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); } + // let queryLike = `CONCAT( + // IFNULL(orgChild4.orgChild4ShortName, '')," ", + // IFNULL(current_holders.posMasterNo , '') + // ) LIKE :keyword OR CONCAT( + // IFNULL(orgChild3.orgChild3ShortName, '')," ", + // IFNULL(current_holders.posMasterNo , '') + // ) LIKE :keyword OR CONCAT( + // IFNULL(orgChild2.orgChild2ShortName, '')," ", + // IFNULL(current_holders.posMasterNo , '') + // ) LIKE :keyword OR CONCAT( + // IFNULL(orgChild1.orgChild1ShortName, '')," ", + // IFNULL(current_holders.posMasterNo , '') + // ) LIKE :keyword OR CONCAT( + // IFNULL(orgRoot.orgRootShortName, '')," ", + // IFNULL(current_holders.posMasterNo , '') + // ) LIKE :keyword`; + let queryLike = "1=1" + switch (body.fieldName) { + case "citizenId": + queryLike = "profile.citizenId LIKE :keyword"; + break; + + case "fullName": + queryLike = "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword"; + break; + + case "position": + queryLike = "profile.position LIKE :keyword"; + break; + + case "posNo": + 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 + `; + break; + + case "posType": + queryLike = "posType.posTypeName LIKE :keyword"; + break; + + case "posLevel": + queryLike = "posLevel.posLevelName LIKE :keyword"; + break; + + case "organization": + queryLike = "orgRoot.orgRootName LIKE :keyword"; + break; + + default: + queryLike = "1=1" + break; + } + + const [findProfile, total] = await this.profileRepo + .createQueryBuilder("profile") + .leftJoinAndSelect("profile.posType", "posType") + .leftJoinAndSelect("profile.posLevel", "posLevel") + .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") + .where("current_holders.orgRevision = :revisionId", { revisionId: findRevision?.id }) + .andWhere( + _data.root != undefined && _data.root != null + ? _data.root[0] != null + ? `current_holders.orgRootId IN (:...root)` + : `current_holders.orgRootId is null` + : "1=1", + { root: _data.root }, + ) + .andWhere( + _data.child1 != undefined && _data.child1 != null + ? _data.child1[0] != null + ? `current_holders.orgChild1Id IN (:...child1)` + : `current_holders.orgChild1Id is null` + : "1=1", + { child1: _data.child1 }, + ) + .andWhere( + _data.child2 != undefined && _data.child2 != null + ? _data.child2[0] != null + ? `current_holders.orgChild2Id IN (:...child2)` + : `current_holders.orgChild2Id is null` + : "1=1", + { child2: _data.child2 }, + ) + .andWhere( + _data.child3 != undefined && _data.child3 != null + ? _data.child3[0] != null + ? `current_holders.orgChild3Id IN (:...child3)` + : `current_holders.orgChild3Id is null` + : "1=1", + { child3: _data.child3 }, + ) + .andWhere( + _data.child4 != undefined && _data.child4 != null + ? _data.child4[0] != null + ? `current_holders.orgChild4Id IN (:...child4)` + : `current_holders.orgChild4Id is null` + : "1=1", + { child4: _data.child4 }, + ) + .andWhere( + new Brackets((qb) => { + qb.orWhere(body.keyword ? queryLike : "1=1", { keyword: `%${body.keyword}%` }); + }), + ) + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); + + // const findRevision = await this.orgRevisionRepo.findOne({ + // where: { orgRevisionIsCurrent: true }, + // }); + // if (!findRevision) { + // throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); + // } const mapDataProfile = await Promise.all( findProfile.map(async (item: Profile) => { diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index a905c452..c0db0ae8 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -4010,243 +4010,127 @@ export class ProfileEmployeeController extends Controller { */ @Post("search-personal") async getProfileBySearchKeyword( + @Request() request: RequestWithUser, @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Body() body: { fieldName: string; keyword?: string; + system?: string; }, ) { - let findProfile: any; - let total: any; - let revision = await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true } }); - const skip = (page - 1) * pageSize; - const take = pageSize; - let queryLike = `CONCAT( - IFNULL(orgChild4.orgChild4ShortName, ''), " ", - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgChild3.orgChild3ShortName, ''), " ", - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgChild2.orgChild2ShortName, ''), " ", - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgChild1.orgChild1ShortName, ''), " ", - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword OR CONCAT( - IFNULL(orgRoot.orgRootShortName, ''), " ", - IFNULL(current_holders.posMasterNo , '') - ) LIKE :keyword`; - - switch (body.fieldName) { - case "citizenId": - [findProfile, total] = await this.profileRepo.findAndCount({ - where: { - citizenId: Like(`%${body.keyword}%`), - current_holders: { - orgRevisionId: revision?.id, - }, - }, - relations: [ - "posType", - "posLevel", - "current_holders", - "profileSalary", - "current_holders.orgRoot", - "current_holders.orgChild1", - "current_holders.orgChild2", - "current_holders.orgChild3", - "current_holders.orgChild4", - ], - skip, - take, - }); - break; - - case "fullName": - [findProfile, total] = await this.profileRepo - .createQueryBuilder("profile") - .leftJoinAndSelect("profile.posType", "posType") - .leftJoinAndSelect("profile.posLevel", "posLevel") - .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") - .where("current_holders.orgRevision = :revisionId", { revisionId: revision?.id }) - .andWhere( - "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword", - { keyword: `%${body.keyword}%` }, - ) - .skip(skip) - .take(take) - .getManyAndCount(); - break; - - case "position": - [findProfile, total] = await this.profileRepo.findAndCount({ - where: { - position: Like(`%${body.keyword}%`), - current_holders: { - orgRevisionId: revision?.id, - }, - }, - relations: [ - "posType", - "posLevel", - "current_holders", - "profileSalary", - "current_holders.orgRoot", - "current_holders.orgChild1", - "current_holders.orgChild2", - "current_holders.orgChild3", - "current_holders.orgChild4", - ], - skip, - take, - }); - break; - - case "posNo": - [findProfile, total] = await this.profileRepo - .createQueryBuilder("profile") - .leftJoinAndSelect("profile.posType", "posType") - .leftJoinAndSelect("profile.posLevel", "posLevel") - .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") - .where("current_holders.orgRevision = :revisionId", { revisionId: revision?.id }) - .andWhere( - new Brackets((qb) => { - qb.orWhere( - body.keyword != undefined && body.keyword != null && body.keyword != "" - ? queryLike - : "1=1", - { - keyword: `%${body.keyword}%`, - }, - ); - }), - ) - .skip(skip) - .take(take) - .getManyAndCount(); - break; - - case "posType": - [findProfile, total] = await this.profileRepo.findAndCount({ - where: { - posType: { - posTypeName: Like(`%${body.keyword}%`), - }, - current_holders: { - orgRevisionId: revision?.id, - }, - }, - relations: [ - "posType", - "posLevel", - "current_holders", - "profileSalary", - "current_holders.orgRoot", - "current_holders.orgChild1", - "current_holders.orgChild2", - "current_holders.orgChild3", - "current_holders.orgChild4", - ], - skip, - take, - }); - break; - - // case "posLevel": - // [findProfile, total] = await this.profileRepo.findAndCount({ - // where: { - // posLevel: { - // posLevelName: Like(`%${body.keyword}%`), - // }, - // current_holders: { - // orgRevisionId: revision?.id, - // }, - // }, - // relations: [ - // "posType", - // "posLevel", - // "current_holders", - // "profileSalary", - // "current_holders.orgRoot", - // "current_holders.orgChild1", - // "current_holders.orgChild2", - // "current_holders.orgChild3", - // "current_holders.orgChild4", - // ], - // skip, - // take, - // }); - // break; - - case "organization": - [findProfile, total] = await this.profileRepo.findAndCount({ - where: { - current_holders: { - orgRevisionId: revision?.id, - orgRoot: { - orgRootName: Like(`%${body.keyword}%`), - }, - }, - }, - relations: [ - "posType", - "posLevel", - "current_holders", - "profileSalary", - "current_holders.orgRoot", - "current_holders.orgChild1", - "current_holders.orgChild2", - "current_holders.orgChild3", - "current_holders.orgChild4", - ], - skip, - take, - }); - break; - - default: - [findProfile, total] = await this.profileRepo.findAndCount({ - where: { - current_holders: { - orgRevisionId: revision?.id, - }, - }, - relations: [ - "posType", - "posLevel", - "current_holders", - "profileSalary", - "current_holders.orgRoot", - "current_holders.orgChild1", - "current_holders.orgChild2", - "current_holders.orgChild3", - "current_holders.orgChild4", - ], - skip, - take, - }); - break; - } - - const findRevision = await this.orgRevisionRepo.findOne({ - where: { orgRevisionIsCurrent: true }, - }); + // ค้นหารายชื่อถ้าไม่ส่ง system มาให้ default ตามทะเบียนประวัติ + let _system:string ="SYS_REGISTRY_EMP"; + if(body.system) + _system = body.system; + let _data = await new permission().PermissionOrgList(request, _system); + const findRevision = await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true } }); if (!findRevision) { throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); } + let queryLike = "1=1" + switch (body.fieldName) { + case "citizenId": + queryLike = "profile.citizenId LIKE :keyword"; + break; + + case "fullName": + queryLike = "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword"; + break; + + case "position": + queryLike = "profile.position LIKE :keyword"; + break; + + case "posNo": + 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 + `; + break; + + case "posType": + queryLike = "posType.posTypeName LIKE :keyword"; + break; + + case "posLevel": + queryLike = "posLevel.posLevelName LIKE :keyword"; + break; + + case "organization": + queryLike = "orgRoot.orgRootName LIKE :keyword"; + break; + + default: + queryLike = "1=1" + break; + } + + const [findProfile, total] = await this.profileRepo + .createQueryBuilder("profile") + .leftJoinAndSelect("profile.posType", "posType") + .leftJoinAndSelect("profile.posLevel", "posLevel") + .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") + .where("current_holders.orgRevision = :revisionId", { revisionId: findRevision?.id }) + .andWhere( + _data.root != undefined && _data.root != null + ? _data.root[0] != null + ? `current_holders.orgRootId IN (:...root)` + : `current_holders.orgRootId is null` + : "1=1", + { root: _data.root }, + ) + .andWhere( + _data.child1 != undefined && _data.child1 != null + ? _data.child1[0] != null + ? `current_holders.orgChild1Id IN (:...child1)` + : `current_holders.orgChild1Id is null` + : "1=1", + { child1: _data.child1 }, + ) + .andWhere( + _data.child2 != undefined && _data.child2 != null + ? _data.child2[0] != null + ? `current_holders.orgChild2Id IN (:...child2)` + : `current_holders.orgChild2Id is null` + : "1=1", + { child2: _data.child2 }, + ) + .andWhere( + _data.child3 != undefined && _data.child3 != null + ? _data.child3[0] != null + ? `current_holders.orgChild3Id IN (:...child3)` + : `current_holders.orgChild3Id is null` + : "1=1", + { child3: _data.child3 }, + ) + .andWhere( + _data.child4 != undefined && _data.child4 != null + ? _data.child4[0] != null + ? `current_holders.orgChild4Id IN (:...child4)` + : `current_holders.orgChild4Id is null` + : "1=1", + { child4: _data.child4 }, + ) + .andWhere( + new Brackets((qb) => { + qb.orWhere(body.keyword ? queryLike : "1=1", { keyword: `%${body.keyword}%` }); + }), + ) + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); const mapDataProfile = await Promise.all( findProfile.map(async (item: ProfileEmployee) => { diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index bcb3bad5..3cfe9d38 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -2174,97 +2174,108 @@ export class ProfileEmployeeTempController extends Controller { */ @Post("search-personal") async getProfileBySearchKeyword( + @Request() request: RequestWithUser, @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Body() body: { fieldName: string; keyword?: string; + system?: string; }, ) { - let findProfile: any; - let total: any; - const skip = (page - 1) * pageSize; - const take = pageSize; - switch (body.fieldName) { - case "citizenId": - [findProfile, total] = await this.profileRepo.findAndCount({ - where: { citizenId: Like(`%${body.keyword}%`) }, - relations: [ - "posType", - "posLevel", - "current_holders", - "current_holders.orgRoot", - "current_holders.orgChild1", - "current_holders.orgChild2", - "current_holders.orgChild3", - "current_holders.orgChild4", - ], - skip, - take, - }); - break; - - case "firstname": - [findProfile, total] = await this.profileRepo.findAndCount({ - where: { firstName: Like(`%${body.keyword}%`) }, - relations: [ - "posType", - "posLevel", - "current_holders", - "current_holders.orgRoot", - "current_holders.orgChild1", - "current_holders.orgChild2", - "current_holders.orgChild3", - "current_holders.orgChild4", - ], - skip, - take, - }); - break; - - case "lastname": - [findProfile, total] = await this.profileRepo.findAndCount({ - where: { lastName: Like(`%${body.keyword}%`) }, - relations: [ - "posType", - "posLevel", - "current_holders", - "current_holders.orgRoot", - "current_holders.orgChild1", - "current_holders.orgChild2", - "current_holders.orgChild3", - "current_holders.orgChild4", - ], - skip, - take, - }); - break; - - default: - [findProfile, total] = await this.profileRepo.findAndCount({ - relations: [ - "posType", - "posLevel", - "current_holders", - "current_holders.orgRoot", - "current_holders.orgChild1", - "current_holders.orgChild2", - "current_holders.orgChild3", - "current_holders.orgChild4", - ], - skip, - take, - }); - break; - } - - const findRevision = await this.orgRevisionRepo.findOne({ - where: { orgRevisionIsCurrent: true }, - }); + // ค้นหารายชื่อถ้าไม่ส่ง system มาให้ default ตามทะเบียนประวัติ + let _system:string ="SYS_REGISTRY_TEMP"; + if(body.system) + _system = body.system; + let _data = await new permission().PermissionOrgList(request, _system); + const findRevision = await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true } }); if (!findRevision) { throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); } + let queryLike = "1=1" + switch (body.fieldName) { + case "citizenId": + queryLike = "profile.citizenId LIKE :keyword"; + break; + + case "firstname": + queryLike = "profile.firstName LIKE :keyword"; + break; + + case "lastname": + queryLike = "profile.lastName LIKE :keyword"; + break; + + case "fullName": + queryLike = "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword"; + break; + + default: + queryLike = "1=1" + break; + } + + const [findProfile, total] = await this.profileRepo + .createQueryBuilder("profile") + .leftJoinAndSelect("profile.posType", "posType") + .leftJoinAndSelect("profile.posLevel", "posLevel") + .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") + .where("current_holders.orgRevision = :revisionId", { revisionId: findRevision?.id }) + .andWhere("profile.employeeClass = :employeeClass", { employeeClass: "TEMP" }) + .andWhere( + _data.root != undefined && _data.root != null + ? _data.root[0] != null + ? `current_holders.orgRootId IN (:...root)` + : `current_holders.orgRootId is null` + : "1=1", + { root: _data.root }, + ) + .andWhere( + _data.child1 != undefined && _data.child1 != null + ? _data.child1[0] != null + ? `current_holders.orgChild1Id IN (:...child1)` + : `current_holders.orgChild1Id is null` + : "1=1", + { child1: _data.child1 }, + ) + .andWhere( + _data.child2 != undefined && _data.child2 != null + ? _data.child2[0] != null + ? `current_holders.orgChild2Id IN (:...child2)` + : `current_holders.orgChild2Id is null` + : "1=1", + { child2: _data.child2 }, + ) + .andWhere( + _data.child3 != undefined && _data.child3 != null + ? _data.child3[0] != null + ? `current_holders.orgChild3Id IN (:...child3)` + : `current_holders.orgChild3Id is null` + : "1=1", + { child3: _data.child3 }, + ) + .andWhere( + _data.child4 != undefined && _data.child4 != null + ? _data.child4[0] != null + ? `current_holders.orgChild4Id IN (:...child4)` + : `current_holders.orgChild4Id is null` + : "1=1", + { child4: _data.child4 }, + ) + .andWhere( + new Brackets((qb) => { + qb.orWhere(body.keyword ? queryLike : "1=1", { keyword: `%${body.keyword}%` }); + }), + ) + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); const mapDataProfile = await Promise.all( findProfile.map(async (item: ProfileEmployee) => { @@ -2369,7 +2380,10 @@ export class ProfileEmployeeTempController extends Controller { posTypeId: item.posTypeId, posTypeName: item.posType?.posTypeName, posLevelId: item.posLevelId, - posLevelName: item.posLevel?.posLevelName, + posLevelName: + item.posLevel == null && item.posType == null + ? null + : `${item.posType?.posTypeShortName} ${item.posLevel?.posLevelName}`, educationDegree: latestProfileEducation != null && latestProfileEducation.educationLevel != null ? latestProfileEducation.educationLevel @@ -3972,7 +3986,10 @@ export class ProfileEmployeeTempController extends Controller { posTypeId: item.posTypeId, posTypeName: item.posType?.posTypeName, posLevelId: item.posLevelId, - posLevelName: item.posLevel?.posLevelName, + posLevelName: + item.posLevel == null && item.posType == null + ? null + : `${item.posType?.posTypeShortName} ${item.posLevel?.posLevelName}`, educationDegree: latestProfileEducation != null && latestProfileEducation.educationLevel != null ? latestProfileEducation.educationLevel From c31c16a0110130f2565b19f857908a30d1d5a392 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 30 Jul 2025 17:42:45 +0700 Subject: [PATCH 4/4] =?UTF-8?q?=E0=B8=84=E0=B9=89=E0=B8=99=E0=B8=AB?= =?UTF-8?q?=E0=B8=B2=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=8A=E0=B8=B7=E0=B9=88?= =?UTF-8?q?=E0=B8=AD=E0=B8=A5=E0=B8=B9=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2?= =?UTF-8?q?=E0=B8=87=E0=B8=8A=E0=B8=B1=E0=B9=88=E0=B8=A7=E0=B8=84=E0=B8=A3?= =?UTF-8?q?=E0=B8=B2=E0=B8=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProfileEmployeeTempController.ts | 171 +++++++++--------- 1 file changed, 86 insertions(+), 85 deletions(-) diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index 3cfe9d38..557d727d 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -2217,118 +2217,119 @@ export class ProfileEmployeeTempController extends Controller { } const [findProfile, total] = await this.profileRepo - .createQueryBuilder("profile") - .leftJoinAndSelect("profile.posType", "posType") - .leftJoinAndSelect("profile.posLevel", "posLevel") - .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") - .where("current_holders.orgRevision = :revisionId", { revisionId: findRevision?.id }) - .andWhere("profile.employeeClass = :employeeClass", { employeeClass: "TEMP" }) - .andWhere( - _data.root != undefined && _data.root != null - ? _data.root[0] != null - ? `current_holders.orgRootId IN (:...root)` - : `current_holders.orgRootId is null` - : "1=1", - { root: _data.root }, - ) - .andWhere( - _data.child1 != undefined && _data.child1 != null - ? _data.child1[0] != null - ? `current_holders.orgChild1Id IN (:...child1)` - : `current_holders.orgChild1Id is null` - : "1=1", - { child1: _data.child1 }, - ) - .andWhere( - _data.child2 != undefined && _data.child2 != null - ? _data.child2[0] != null - ? `current_holders.orgChild2Id IN (:...child2)` - : `current_holders.orgChild2Id is null` - : "1=1", - { child2: _data.child2 }, - ) - .andWhere( - _data.child3 != undefined && _data.child3 != null - ? _data.child3[0] != null - ? `current_holders.orgChild3Id IN (:...child3)` - : `current_holders.orgChild3Id is null` - : "1=1", - { child3: _data.child3 }, - ) - .andWhere( - _data.child4 != undefined && _data.child4 != null - ? _data.child4[0] != null - ? `current_holders.orgChild4Id IN (:...child4)` - : `current_holders.orgChild4Id is null` - : "1=1", - { child4: _data.child4 }, - ) - .andWhere( - new Brackets((qb) => { - qb.orWhere(body.keyword ? queryLike : "1=1", { keyword: `%${body.keyword}%` }); - }), - ) - .skip((page - 1) * pageSize) - .take(pageSize) - .getManyAndCount(); + .createQueryBuilder("profile") + .leftJoinAndSelect("profile.posType", "posType") + .leftJoinAndSelect("profile.posLevel", "posLevel") + // .leftJoinAndSelect("profile.current_holders", "current_holders") + .leftJoinAndSelect("profile.current_holderTemps", "current_holderTemps") + .leftJoinAndSelect("current_holderTemps.orgRoot", "orgRoot") + .leftJoinAndSelect("current_holderTemps.orgChild1", "orgChild1") + .leftJoinAndSelect("current_holderTemps.orgChild2", "orgChild2") + .leftJoinAndSelect("current_holderTemps.orgChild3", "orgChild3") + .leftJoinAndSelect("current_holderTemps.orgChild4", "orgChild4") + .where("current_holderTemps.orgRevision = :revisionId", { revisionId: findRevision?.id }) + .andWhere("profile.employeeClass = :employeeClass", { employeeClass: "TEMP" }) + .andWhere( + _data.root != undefined && _data.root != null + ? _data.root[0] != null + ? `current_holderTemps.orgRootId IN (:...root)` + : `current_holderTemps.orgRootId is null` + : "1=1", + { root: _data.root }, + ) + .andWhere( + _data.child1 != undefined && _data.child1 != null + ? _data.child1[0] != null + ? `current_holderTemps.orgChild1Id IN (:...child1)` + : `current_holderTemps.orgChild1Id is null` + : "1=1", + { child1: _data.child1 }, + ) + .andWhere( + _data.child2 != undefined && _data.child2 != null + ? _data.child2[0] != null + ? `current_holderTemps.orgChild2Id IN (:...child2)` + : `current_holderTemps.orgChild2Id is null` + : "1=1", + { child2: _data.child2 }, + ) + .andWhere( + _data.child3 != undefined && _data.child3 != null + ? _data.child3[0] != null + ? `current_holderTemps.orgChild3Id IN (:...child3)` + : `current_holderTemps.orgChild3Id is null` + : "1=1", + { child3: _data.child3 }, + ) + .andWhere( + _data.child4 != undefined && _data.child4 != null + ? _data.child4[0] != null + ? `current_holderTemps.orgChild4Id IN (:...child4)` + : `current_holderTemps.orgChild4Id is null` + : "1=1", + { child4: _data.child4 }, + ) + .andWhere( + new Brackets((qb) => { + qb.orWhere(body.keyword ? queryLike : "1=1", { keyword: `%${body.keyword}%` }); + }), + ) + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); const mapDataProfile = await Promise.all( findProfile.map(async (item: ProfileEmployee) => { const fullName = `${item.prefix} ${item.firstName} ${item.lastName}`; const shortName = - item.current_holders.length == 0 + item.current_holderTemps.length == 0 ? null - : item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4 != + : item.current_holderTemps.find((x) => x.orgRevisionId == findRevision.id) != null && + item.current_holderTemps.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 != + ? `${item.current_holderTemps.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4.orgChild4ShortName} ${item.current_holderTemps.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : item.current_holderTemps.find((x) => x.orgRevisionId == findRevision.id) != null && + item.current_holderTemps.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) + ? `${item.current_holderTemps.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3.orgChild3ShortName} ${item.current_holderTemps.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : item.current_holderTemps.find((x) => x.orgRevisionId == findRevision.id) != null && + item.current_holderTemps.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) + ? `${item.current_holderTemps.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2.orgChild2ShortName} ${item.current_holderTemps.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : item.current_holderTemps.find((x) => x.orgRevisionId == findRevision.id) != null && + item.current_holderTemps.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) != + ? `${item.current_holderTemps.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1.orgChild1ShortName} ${item.current_holderTemps.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` + : item.current_holderTemps.find((x) => x.orgRevisionId == findRevision.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision.id) + item.current_holderTemps.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}` + ? `${item.current_holderTemps.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot.orgRootShortName} ${item.current_holderTemps.find((x) => x.orgRevisionId == findRevision.id)?.posMasterNo}` : null; const root = - item.current_holders.length == 0 || - (item.current_holders.find((x) => x.orgRevisionId == findRevision.id) != null && - item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null) + item.current_holderTemps.length == 0 || + (item.current_holderTemps.find((x) => x.orgRevisionId == findRevision.id) != null && + item.current_holderTemps.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot == null) ? null - : item.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot; + : item.current_holderTemps.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot; - const rootHolder = item.current_holders?.find( + const rootHolder = item.current_holderTemps?.find( (x) => x.orgRevisionId == findRevision.id, )?.orgRoot; - const child1Holder = item.current_holders?.find( + const child1Holder = item.current_holderTemps?.find( (x) => x.orgRevisionId == findRevision.id, )?.orgChild1; - const child2Holder = item.current_holders?.find( + const child2Holder = item.current_holderTemps?.find( (x) => x.orgRevisionId == findRevision.id, )?.orgChild2; - const child3Holder = item.current_holders?.find( + const child3Holder = item.current_holderTemps?.find( (x) => x.orgRevisionId == findRevision.id, )?.orgChild3; - const child4Holder = item.current_holders?.find( + const child4Holder = item.current_holderTemps?.find( (x) => x.orgRevisionId == findRevision.id, )?.orgChild4; - const posMasterNo = item.current_holders?.find( + const posMasterNo = item.current_holderTemps?.find( (x) => x.orgRevisionId == findRevision.id, )?.posMasterNo;