checkpoint

This commit is contained in:
AdisakKanthawilang 2025-04-18 11:15:53 +07:00
parent 41ebcee967
commit 2f0d86ed58
2 changed files with 19 additions and 11 deletions

View file

@ -2496,25 +2496,25 @@ export class SalaryPeriodController extends Controller {
await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee, { data: request }); await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee, { data: request });
await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee, { data: request }); await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee, { data: request });
let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id"); let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id");
let total = 10000; let total = 1000;
// let _orgProfiles = await new CallAPI().PostData(request, "/org/unauthorize/salary/gen", { // let _orgProfiles = await new CallAPI().PostData(request, "/org/unauthorize/salary/gen", {
let _orgProfiles = await new CallAPI().PostData(request, "/org/unauthorize/new-salary/gen", { let _orgProfiles = await new CallAPI().PostData(request, "/org/unauthorize/new-salary/gen", {
page: 1, page: 1,
pageSize: 10000, pageSize: 1000,
keyword: "", keyword: "",
year: salaryPeriod.year, year: salaryPeriod.year,
period: salaryPeriod.period, period: salaryPeriod.period,
}); });
let orgProfiles = _orgProfiles.data; let orgProfiles = _orgProfiles.data;
total = _orgProfiles.total; total = _orgProfiles.total;
if (total > 10000) { if (total > 1000) {
const page = Math.ceil(total / 10000); const page = Math.ceil(total / 1000);
for (let index = 2; index <= page; index++) { for (let index = 2; index <= page; index++) {
await new CallAPI() await new CallAPI()
// .PostData(request, "/org/unauthorize/salary/gen", { // .PostData(request, "/org/unauthorize/salary/gen", {
.PostData(request, "/org/unauthorize/new-salary/gen", { .PostData(request, "/org/unauthorize/new-salary/gen", {
page: index, page: index,
pageSize: 10000, pageSize: 1000,
keyword: "", keyword: "",
year: salaryPeriod.year, year: salaryPeriod.year,
period: salaryPeriod.period, period: salaryPeriod.period,
@ -2524,7 +2524,7 @@ export class SalaryPeriodController extends Controller {
}); });
} }
} }
total = 10000; total = 1000;
let orgProfileEmployees: any; let orgProfileEmployees: any;
let _orgProfileEmployees = await new CallAPI().PostData( let _orgProfileEmployees = await new CallAPI().PostData(
request, request,
@ -2532,7 +2532,7 @@ export class SalaryPeriodController extends Controller {
"/org/unauthorize/new-salary/employee/gen", "/org/unauthorize/new-salary/employee/gen",
{ {
page: 1, page: 1,
pageSize: 10000, pageSize: 1000,
keyword: "", keyword: "",
year: salaryPeriod.year, year: salaryPeriod.year,
period: salaryPeriod.period, period: salaryPeriod.period,
@ -2540,14 +2540,14 @@ export class SalaryPeriodController extends Controller {
); );
orgProfileEmployees = _orgProfileEmployees.data; orgProfileEmployees = _orgProfileEmployees.data;
total = _orgProfileEmployees.total; total = _orgProfileEmployees.total;
if (total > 10000) { if (total > 1000) {
const page = Math.ceil(total / 10000); const page = Math.ceil(total / 1000);
for (let index = 2; index <= page; index++) { for (let index = 2; index <= page; index++) {
await new CallAPI() await new CallAPI()
// .PostData(request, "/org/unauthorize/salary/employee/gen", { // .PostData(request, "/org/unauthorize/salary/employee/gen", {
.PostData(request, "/org/unauthorize/new-salary/employee/gen", { .PostData(request, "/org/unauthorize/new-salary/employee/gen", {
page: index, page: index,
pageSize: 10000, pageSize: 1000,
keyword: "", keyword: "",
year: salaryPeriod.year, year: salaryPeriod.year,
period: salaryPeriod.period, period: salaryPeriod.period,
@ -2630,6 +2630,7 @@ export class SalaryPeriodController extends Controller {
}), }),
); );
if (salaryPeriod.period != "SPECIAL") { if (salaryPeriod.period != "SPECIAL") {
console.log(`step1`)
await Promise.all( await Promise.all(
orgProfiles.map(async (profile: any) => { orgProfiles.map(async (profile: any) => {
let group = "GROUP1"; let group = "GROUP1";
@ -2643,6 +2644,7 @@ export class SalaryPeriodController extends Controller {
) { ) {
group = "GROUP2"; group = "GROUP2";
} }
console.log(`step2`)
const salaryOrgNew = await this.salaryOrgRepository.findOne({ const salaryOrgNew = await this.salaryOrgRepository.findOne({
where: { where: {
salaryPeriodId: salaryPeriod.id, salaryPeriodId: salaryPeriod.id,
@ -2651,8 +2653,9 @@ export class SalaryPeriodController extends Controller {
group: group, group: group,
}, },
}); });
console.log(`step3`)
if (salaryOrgNew != null) { if (salaryOrgNew != null) {
console.log(`step4`)
let salaryProfileNew = Object.assign(new SalaryProfile(), profile); let salaryProfileNew = Object.assign(new SalaryProfile(), profile);
delete salaryProfileNew.id; delete salaryProfileNew.id;
@ -2668,6 +2671,7 @@ export class SalaryPeriodController extends Controller {
salaryProfileNew.lastUpdatedAt = new Date(); salaryProfileNew.lastUpdatedAt = new Date();
if (snapshot == "SNAP2") { if (snapshot == "SNAP2") {
console.log(`step5`)
const salaryOrgOld = await this.salaryOrgRepository.find({ const salaryOrgOld = await this.salaryOrgRepository.find({
where: { salaryPeriodId: salaryPeriod.id, snapshot: "SNAP1" }, where: { salaryPeriodId: salaryPeriod.id, snapshot: "SNAP1" },
}); });
@ -2688,6 +2692,7 @@ export class SalaryPeriodController extends Controller {
salaryProfileNew.isReserve = salaryOld == null ? false : salaryOld.isReserve; salaryProfileNew.isReserve = salaryOld == null ? false : salaryOld.isReserve;
salaryProfileNew.isRetired = salaryOld == null ? false : salaryOld.isRetired; salaryProfileNew.isRetired = salaryOld == null ? false : salaryOld.isRetired;
} }
console.log(`step6`)
await this.salaryProfileRepository.save(salaryProfileNew, { data: request }); await this.salaryProfileRepository.save(salaryProfileNew, { data: request });
setLogDataDiff(request, { before: beforeSalaryProfileNew, after: salaryProfileNew }); setLogDataDiff(request, { before: beforeSalaryProfileNew, after: salaryProfileNew });
console.log(`✅ [SNAP: ${snapshot}] บันทึก SalaryProfile: ${salaryProfileNew.citizenId} (${salaryProfileNew.fullName ?? "-"})`); console.log(`✅ [SNAP: ${snapshot}] บันทึก SalaryProfile: ${salaryProfileNew.citizenId} (${salaryProfileNew.fullName ?? "-"})`);

View file

@ -27,6 +27,8 @@ class CallAPI {
api_key: process.env.API_KEY, api_key: process.env.API_KEY,
}, },
}); });
console.log("getting data...");
if(log) addLogSequence(request, { if(log) addLogSequence(request, {
action: "request", action: "request",
status: "success", status: "success",
@ -64,6 +66,7 @@ class CallAPI {
api_key: process.env.API_KEY, api_key: process.env.API_KEY,
}, },
}); });
console.log("processing data...");
addLogSequence(request, { addLogSequence(request, {
action: "request", action: "request",
status: "success", status: "success",