diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index 22db76e..59a70c0 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -1611,7 +1611,7 @@ export class SalaryPeriodController extends Controller { "CONCAT(profile.prefix,profile.firstName,' ',profile.lastName) LIKE :keyword", { keyword: `%${body.keyword}%` }, ) - .orWhere("CONCAT(profile.orgShortName,profile.posMasterNo) LIKE :keyword", { + .orWhere("CONCAT(profile.orgShortName,' ',profile.posMasterNo) LIKE :keyword", { keyword: `%${body.keyword}%`, }) // .orWhere("profile.citizenId LIKE :keyword", { keyword: `%${body.keyword}%` }) @@ -2821,10 +2821,9 @@ export class SalaryPeriodController extends Controller { //**********************/ console.log("mlength", orgProfileEmployees.length); - // const profilesEmpToSave: SalaryProfileEmployee[] = []; + const profilesEmpToSave: SalaryProfileEmployee[] = []; console.time("⏱ SalaryProfileEmployee - Total Time"); - await Promise.all( - orgProfileEmployees.map(async (profile: any) => { + for (const profile of orgProfileEmployees) { const salaryOrgNew = await this.salaryOrgEmployeeRepository.findOne({ where: { salaryPeriodId: salaryPeriod.id, @@ -2883,21 +2882,28 @@ export class SalaryPeriodController extends Controller { salaryProfileNew.isRetired = salaryOld == null ? false : salaryOld.isRetired; salaryProfileNew.isGood = salaryOld == null ? false : salaryOld.isGood; } - // profilesEmpToSave.push(salaryProfileNew); + profilesEmpToSave.push(salaryProfileNew); + + await this.salaryProfileEmployeeRepository + .createQueryBuilder() + .insert() + .into(SalaryProfileEmployee) + .values(profilesEmpToSave) + .orIgnore() + .execute(); //console.log(`step10`); // console.log( // `✅ [SNAP: ${snapshot}] Push SalaryProfileEmployee: ${salaryProfileNew.citizenId} (${salaryProfileNew.fullName ?? "-"})`, // ); - await this.salaryProfileEmployeeRepository.save(salaryProfileNew, { data: request }); + // await this.salaryProfileEmployeeRepository.save(salaryProfileNew, { data: request }); // await this.salaryProfileEmployeeRepository.save(profilesEmpToSave, { chunk: 100, data: request }); - setLogDataDiff(request, { before: beforeSalaryProfileNew, after: salaryProfileNew }); + // setLogDataDiff(request, { before: beforeSalaryProfileNew, after: salaryProfileNew }); } else { console.warn( `⚠️ [SNAP: ${snapshot}] ไม่พบ salaryOrgEmployee สำหรับ rootId: ${profile.rootId}`, ); } - }), - ); + }; console.timeEnd("⏱ SalaryProfileEmployee - Total Time"); } diff --git a/src/controllers/SalaryPeriodEmployeeController.ts b/src/controllers/SalaryPeriodEmployeeController.ts index 43fe5d6..5ec3200 100644 --- a/src/controllers/SalaryPeriodEmployeeController.ts +++ b/src/controllers/SalaryPeriodEmployeeController.ts @@ -1135,7 +1135,7 @@ export class SalaryPeriodEmployeeController extends Controller { "CONCAT(profile.prefix,profile.firstName,' ',profile.lastName) LIKE :keyword", { keyword: `%${body.keyword}%` }, ) - .orWhere("CONCAT(profile.orgShortName,profile.posMasterNo) LIKE :keyword", { + .orWhere("CONCAT(profile.orgShortName,' ',profile.posMasterNo) LIKE :keyword", { keyword: `%${body.keyword}%`, }) .orWhere("CONCAT(profile.orgShortName,' ',profile.posMasterNo) LIKE :keyword", {