Merge branch 'develop' into dev
All checks were successful
Build & Deploy on Dev / build (push) Successful in 55s

This commit is contained in:
harid 2026-06-29 14:31:57 +07:00
commit ddbfc3e25e

View file

@ -9078,8 +9078,7 @@ export class ReportController extends Controller {
body: { body: {
refIds: { refIds: {
refId: string; refId: string;
// commandAffectDate: Date | null;//เก่า commandDateAffect: Date | null;
commandDateAffect: Date | null; //ใหม่ (ปรับตาม rabbitMQ ORG)
commandNo: string | null; commandNo: string | null;
commandYear: number | null; commandYear: number | null;
commandId: string | null; commandId: string | null;
@ -9095,16 +9094,79 @@ export class ReportController extends Controller {
}, },
@Request() request: RequestWithUser, @Request() request: RequestWithUser,
) { ) {
await Promise.all( // ═══════════════════════════════════════════════════════════════
// old circle flow (เก็บไว้อ้างอิง — ลบการใช้งานจริงออกแล้ว)
// ═══════════════════════════════════════════════════════════════
// await Promise.all(
// body.refIds.map(async (v) => {
// const salary = await this.salaryProfileRepository.findOne({
// where: { id: v.refId },
// });
// if (salary != null) {
// // เดิม: ยิง callback เข้า org เพื่อให้ org สร้าง salary record
// await new CallAPI()
// .PostData(request, "/org/profile/salary/update", {
// profileId: salary.profileId,
// commandDateAffect: v.commandDateAffect,
// commandDateSign: v.commandDateSign,
// amount: v.amount,
// amountSpecial: v.amountSpecial,
// positionSalaryAmount: v.positionSalaryAmount,
// mouthSalaryAmount: v.mouthSalaryAmount,
// posNo: salary.posMasterNo.toString(),
// posNoAbb: salary.orgShortName,
// positionName: salary.position,
// positionExecutive: salary.posExecutive,
// positionExecutiveField: salary.positionExecutiveField,
// positionArea: salary.positionArea,
// positionType: salary.posType,
// positionLevel: salary.posLevel,
// commandId: v.commandId,
// remark: v.remark,
// orgRoot: salary.root,
// orgChild1: salary.child1,
// orgChild2: salary.child2,
// orgChild3: salary.child3,
// orgChild4: salary.child4,
// commandCode: v.commandCode,
// commandName: v.commandName,
// commandNo: v.commandNo,
// commandYear: v.commandYear,
// })
// // เดิม: set status33 ใน .then() หลัง org ตอบกลับสำเร็จเท่านั้น
// .then(async () => {
// const before = null;
// salary.status33 = "DONE";
// salary.lastUpdateUserId = request.user.sub;
// salary.lastUpdateFullName = request.user.name;
// salary.lastUpdatedAt = new Date();
// await this.salaryProfileRepository.save(salary, { data: request });
// setLogDataDiff(request, { before, after: salary });
// });
// }
// }),
// );
// return new HttpSuccess();
// ═══════════════════════════════════════════════════════════════
// new linear flow
// ═══════════════════════════════════════════════════════════════
// เปลี่ยน: ไม่ยิง callback เข้า org แล้ว → ทำงานของตัวเอง (set status) แล้ว return data
// ให้ org ทำงานต่อ (org AMQ จะเรียก ExecuteSalaryReportService เองหลังได้รับ response)
const result = await Promise.all(
body.refIds.map(async (v) => { body.refIds.map(async (v) => {
const salary = await this.salaryProfileRepository.findOne({ const salary = await this.salaryProfileRepository.findOne({ where: { id: v.refId } });
where: {
id: v.refId,
},
});
if (salary != null) { if (salary != null) {
await new CallAPI() // 1) set status33 = DONE (ย้ายขึ้นมาทำก่อนเลย ไม่ต้องรอ org ตอบกลับ)
.PostData(request, "/org/profile/salary/update", { salary.status33 = "DONE";
salary.lastUpdateUserId = request.user.sub;
salary.lastUpdateFullName = request.user.name;
salary.lastUpdatedAt = new Date();
await this.salaryProfileRepository.save(salary, { data: request });
setLogDataDiff(request, { before: null, after: salary });
// 2) return ข้อมูลที่ org ต้องการสร้าง ProfileSalary (shape เดียวกับที่เคย PostData)
return {
profileId: salary.profileId, profileId: salary.profileId,
commandDateAffect: v.commandDateAffect, commandDateAffect: v.commandDateAffect,
commandDateSign: v.commandDateSign, commandDateSign: v.commandDateSign,
@ -9131,20 +9193,12 @@ export class ReportController extends Controller {
commandName: v.commandName, commandName: v.commandName,
commandNo: v.commandNo, commandNo: v.commandNo,
commandYear: v.commandYear, commandYear: v.commandYear,
}) };
.then(async () => {
const before = null;
salary.status33 = "DONE";
salary.lastUpdateUserId = request.user.sub;
salary.lastUpdateFullName = request.user.name;
salary.lastUpdatedAt = new Date();
await this.salaryProfileRepository.save(salary, { data: request });
setLogDataDiff(request, { before, after: salary });
});
} }
return null; // refId ที่ไม่พบ salary → กรองออก (เหมือนเดิมที่ข้ามไป)
}), }),
); );
return new HttpSuccess(); return result.filter(Boolean); // return array ของ salary data ให้ org ทำงานต่อ
} }
/** /**
@ -9160,8 +9214,7 @@ export class ReportController extends Controller {
body: { body: {
refIds: { refIds: {
refId: string; refId: string;
// commandAffectDate: Date | null;//เก่า commandDateAffect: Date | null;
commandDateAffect: Date | null; //ใหม่ (ปรับตาม rabbitMQ ORG)
commandNo: string | null; commandNo: string | null;
commandYear: number | null; commandYear: number | null;
commandId: string | null; commandId: string | null;
@ -9177,17 +9230,75 @@ export class ReportController extends Controller {
}, },
@Request() request: RequestWithUser, @Request() request: RequestWithUser,
) { ) {
await Promise.all( // ═══════════════════════════════════════════════════════════════
body.refIds.map(async (v) => { // old circle flow (เก็บไว้อ้างอิง — ลบการใช้งานจริงออกแล้ว)
const salary = await this.salaryProfileRepository.findOne({ // ═══════════════════════════════════════════════════════════════
where: { // await Promise.all(
id: v.refId, // body.refIds.map(async (v) => {
}, // const salary = await this.salaryProfileRepository.findOne({
}); // where: { id: v.refId },
// });
// if (salary != null) {
// await new CallAPI()
// .PostData(request, "/org/profile/salary/update", {
// profileId: salary.profileId,
// commandDateAffect: v.commandDateAffect,
// commandDateSign: v.commandDateSign,
// amount: v.amount,
// amountSpecial: v.amountSpecial,
// positionSalaryAmount: v.positionSalaryAmount,
// mouthSalaryAmount: v.mouthSalaryAmount,
// posNo: salary.posMasterNo.toString(),
// posNoAbb: salary.orgShortName,
// positionName: salary.position,
// positionExecutive: salary.posExecutive,
// positionExecutiveField: salary.positionExecutiveField,
// positionArea: salary.positionArea,
// positionType: salary.posType,
// positionLevel: salary.posLevel,
// commandId: v.commandId,
// remark: v.remark,
// orgRoot: salary.root,
// orgChild1: salary.child1,
// orgChild2: salary.child2,
// orgChild3: salary.child3,
// orgChild4: salary.child4,
// commandCode: v.commandCode,
// commandName: v.commandName,
// commandNo: v.commandNo,
// commandYear: v.commandYear,
// })
// .then(async () => {
// const before = null;
// salary.status34 = "DONE";
// salary.lastUpdateUserId = request.user.sub;
// salary.lastUpdateFullName = request.user.name;
// salary.lastUpdatedAt = new Date();
// await this.salaryProfileRepository.save(salary, { data: request });
// setLogDataDiff(request, { before, after: salary });
// });
// }
// }),
// );
// return new HttpSuccess();
// ═══════════════════════════════════════════════════════════════
// new linear flow
// ═══════════════════════════════════════════════════════════════
const result = await Promise.all(
body.refIds.map(async (v) => {
const salary = await this.salaryProfileRepository.findOne({ where: { id: v.refId } });
if (salary != null) { if (salary != null) {
await new CallAPI() // 1) set status34 = DONE (ย้ายขึ้นมาทำก่อนเลย ไม่ต้องรอ org ตอบกลับ)
.PostData(request, "/org/profile/salary/update", { salary.status34 = "DONE";
salary.lastUpdateUserId = request.user.sub;
salary.lastUpdateFullName = request.user.name;
salary.lastUpdatedAt = new Date();
await this.salaryProfileRepository.save(salary, { data: request });
setLogDataDiff(request, { before: null, after: salary });
// 2) return ข้อมูลที่ org ต้องการสร้าง ProfileSalary (shape เดียวกับที่เคย PostData)
return {
profileId: salary.profileId, profileId: salary.profileId,
commandDateAffect: v.commandDateAffect, commandDateAffect: v.commandDateAffect,
commandDateSign: v.commandDateSign, commandDateSign: v.commandDateSign,
@ -9214,20 +9325,12 @@ export class ReportController extends Controller {
commandName: v.commandName, commandName: v.commandName,
commandNo: v.commandNo, commandNo: v.commandNo,
commandYear: v.commandYear, commandYear: v.commandYear,
}) };
.then(async () => {
const before = null;
salary.status34 = "DONE";
salary.lastUpdateUserId = request.user.sub;
salary.lastUpdateFullName = request.user.name;
salary.lastUpdatedAt = new Date();
await this.salaryProfileRepository.save(salary, { data: request });
setLogDataDiff(request, { before, after: salary });
});
} }
return null;
}), }),
); );
return new HttpSuccess(); return result.filter(Boolean);
} }
/** /**
@ -9243,8 +9346,7 @@ export class ReportController extends Controller {
body: { body: {
refIds: { refIds: {
refId: string; refId: string;
// commandAffectDate: Date | null;//เก่า commandDateAffect: Date | null;
commandDateAffect: Date | null; //ใหม่ (ปรับตาม rabbitMQ ORG)
commandNo: string | null; commandNo: string | null;
commandYear: number | null; commandYear: number | null;
commandId: string | null; commandId: string | null;
@ -9260,17 +9362,76 @@ export class ReportController extends Controller {
}, },
@Request() request: RequestWithUser, @Request() request: RequestWithUser,
) { ) {
await Promise.all( // ═══════════════════════════════════════════════════════════════
body.refIds.map(async (v) => { // old circle flow (เก็บไว้อ้างอิง — ลบการใช้งานจริงออกแล้ว)
const salary = await this.salaryProfileRepository.findOne({ // ═══════════════════════════════════════════════════════════════
where: { // await Promise.all(
id: v.refId, // body.refIds.map(async (v) => {
}, // const salary = await this.salaryProfileRepository.findOne({
}); // where: { id: v.refId },
// });
// if (salary != null) {
// await new CallAPI()
// .PostData(request, "/org/profile/salary/update", {
// profileId: salary.profileId,
// commandDateAffect: v.commandDateAffect,
// commandDateSign: v.commandDateSign,
// amount: v.amount,
// amountSpecial: v.amountSpecial,
// positionSalaryAmount: v.positionSalaryAmount,
// mouthSalaryAmount: v.mouthSalaryAmount,
// posNo: salary.posMasterNo.toString(),
// posNoAbb: salary.orgShortName,
// positionName: salary.position,
// positionExecutive: salary.posExecutive,
// positionExecutiveField: salary.positionExecutiveField,
// positionArea: salary.positionArea,
// positionType: salary.posType,
// positionLevel: salary.posLevel,
// commandId: v.commandId,
// remark: v.remark,
// orgRoot: salary.root,
// orgChild1: salary.child1,
// orgChild2: salary.child2,
// orgChild3: salary.child3,
// orgChild4: salary.child4,
// commandCode: v.commandCode,
// commandName: v.commandName,
// commandNo: v.commandNo,
// commandYear: v.commandYear,
// })
// .then(async () => {
// const before = null;
// salary.status35 = "DONE";
// salary.lastUpdateUserId = request.user.sub;
// salary.lastUpdateFullName = request.user.name;
// salary.lastUpdatedAt = new Date();
// await this.salaryProfileRepository.save(salary, { data: request });
// setLogDataDiff(request, { before, after: salary });
// });
// }
// }),
// );
// return new HttpSuccess();
// ═══════════════════════════════════════════════════════════════
// new linear flow
// ═══════════════════════════════════════════════════════════════
// ใช้ร่วมกับ C-PM-45 (path reuse) — ทั้ง C-PM-35/45 ยิงเข้าที่นี่ ตั้ง status35 เหมือนกัน
const result = await Promise.all(
body.refIds.map(async (v) => {
const salary = await this.salaryProfileRepository.findOne({ where: { id: v.refId } });
if (salary != null) { if (salary != null) {
await new CallAPI() // 1) set status35 = DONE (ย้ายขึ้นมาทำก่อนเลย ไม่ต้องรอ org ตอบกลับ)
.PostData(request, "/org/profile/salary/update", { salary.status35 = "DONE";
salary.lastUpdateUserId = request.user.sub;
salary.lastUpdateFullName = request.user.name;
salary.lastUpdatedAt = new Date();
await this.salaryProfileRepository.save(salary, { data: request });
setLogDataDiff(request, { before: null, after: salary });
// 2) return ข้อมูลที่ org ต้องการสร้าง ProfileSalary (shape เดียวกับที่เคย PostData)
return {
profileId: salary.profileId, profileId: salary.profileId,
commandDateAffect: v.commandDateAffect, commandDateAffect: v.commandDateAffect,
commandDateSign: v.commandDateSign, commandDateSign: v.commandDateSign,
@ -9297,20 +9458,12 @@ export class ReportController extends Controller {
commandName: v.commandName, commandName: v.commandName,
commandNo: v.commandNo, commandNo: v.commandNo,
commandYear: v.commandYear, commandYear: v.commandYear,
}) };
.then(async () => {
const before = null;
salary.status35 = "DONE";
salary.lastUpdateUserId = request.user.sub;
salary.lastUpdateFullName = request.user.name;
salary.lastUpdatedAt = new Date();
await this.salaryProfileRepository.save(salary, { data: request });
setLogDataDiff(request, { before, after: salary });
});
} }
return null;
}), }),
); );
return new HttpSuccess(); return result.filter(Boolean);
} }
/** /**
@ -9326,8 +9479,7 @@ export class ReportController extends Controller {
body: { body: {
refIds: { refIds: {
refId: string; refId: string;
// commandAffectDate: Date | null;//เก่า commandDateAffect: Date | null;
commandDateAffect: Date | null; //ใหม่ (ปรับตาม rabbitMQ ORG)
commandDateSign?: Date | null; commandDateSign?: Date | null;
commandNo: string | null; commandNo: string | null;
commandYear: number | null; commandYear: number | null;
@ -9347,17 +9499,81 @@ export class ReportController extends Controller {
}, },
@Request() request: RequestWithUser, @Request() request: RequestWithUser,
) { ) {
await Promise.all( // ═══════════════════════════════════════════════════════════════
body.refIds.map(async (v) => { // old circle flow (เก็บไว้อ้างอิง — ลบการใช้งานจริงออกแล้ว)
const salary = await this.salaryProfileEmployeeRepository.findOne({ // ═══════════════════════════════════════════════════════════════
where: { // await Promise.all(
id: v.refId, // body.refIds.map(async (v) => {
}, // const salary = await this.salaryProfileEmployeeRepository.findOne({
}); // where: { id: v.refId },
// });
// if (salary != null) {
// await new CallAPI()
// .PostData(request, "/org/profile-employee/salary/update", {
// profileEmployeeId: salary.profileId,
// commandDateAffect: v.commandDateAffect,
// commandDateSign: v.commandDateSign,
// amount: v.amount,
// amountSpecial: v.amountSpecial,
// positionSalaryAmount: v.positionSalaryAmount,
// mouthSalaryAmount: v.mouthSalaryAmount,
// posNo: salary.posMasterNo != null ? salary.posMasterNo.toString() : null,
// posNoAbb: salary.orgShortName,
// positionName: salary.position,
// positionType: salary.posType,
// positionLevel:
// (salary.posTypeShort != null ? salary.posTypeShort + " " : "") +
// (salary.posLevel != null ? salary.posLevel.toString() : ""),
// remark: v.remark,
// orgRoot: salary.root,
// orgChild1: salary.child1,
// orgChild2: salary.child2,
// orgChild3: salary.child3,
// orgChild4: salary.child4,
// commandCode: v.commandCode,
// commandName: v.commandName,
// commandNo: v.commandNo,
// commandYear: v.commandYear,
// commandId: v.commandId,
// salaryLevel:
// salary.salaryLevel && salary.salaryLevelNew
// ? salary.salaryLevelNew
// : salary.salaryLevel,
// group: salary.groupNew ?? salary.group,
// })
// .then(async () => {
// const before = null;
// salary.status36 = "DONE";
// salary.lastUpdateUserId = request.user.sub;
// salary.lastUpdateFullName = request.user.name;
// salary.lastUpdatedAt = new Date();
// await this.salaryProfileEmployeeRepository.save(salary, { data: request });
// setLogDataDiff(request, { before, after: salary });
// });
// }
// }),
// );
// return new HttpSuccess();
// ═══════════════════════════════════════════════════════════════
// new linear flow
// ═══════════════════════════════════════════════════════════════
// ใช้ร่วมกับ C-PM-46 (path reuse) — ทั้ง C-PM-36/46 ยิงเข้าที่นี่ ตั้ง status36 เหมือนกัน
const result = await Promise.all(
body.refIds.map(async (v) => {
const salary = await this.salaryProfileEmployeeRepository.findOne({ where: { id: v.refId } });
if (salary != null) { if (salary != null) {
await new CallAPI() // 1) set status36 = DONE (ย้ายขึ้นมาทำก่อนเลย ไม่ต้องรอ org ตอบกลับ)
.PostData(request, "/org/profile-employee/salary/update", { salary.status36 = "DONE";
salary.lastUpdateUserId = request.user.sub;
salary.lastUpdateFullName = request.user.name;
salary.lastUpdatedAt = new Date();
await this.salaryProfileEmployeeRepository.save(salary, { data: request });
setLogDataDiff(request, { before: null, after: salary });
// 2) return ข้อมูลที่ org ต้องการสร้าง ProfileSalary (shape เดียวกับที่เคย PostData)
// สังเกต: profileEmployeeId (ไม่ใช่ profileId) + salaryLevel/group เพิ่ม
return {
profileEmployeeId: salary.profileId, profileEmployeeId: salary.profileId,
commandDateAffect: v.commandDateAffect, commandDateAffect: v.commandDateAffect,
commandDateSign: v.commandDateSign, commandDateSign: v.commandDateSign,
@ -9384,24 +9600,14 @@ export class ReportController extends Controller {
commandYear: v.commandYear, commandYear: v.commandYear,
commandId: v.commandId, commandId: v.commandId,
salaryLevel: salaryLevel:
salary.salaryLevel && salary.salaryLevelNew salary.salaryLevel && salary.salaryLevelNew ? salary.salaryLevelNew : salary.salaryLevel,
? salary.salaryLevelNew
: salary.salaryLevel,
group: salary.groupNew ?? salary.group, group: salary.groupNew ?? salary.group,
}) };
.then(async () => {
const before = null;
salary.status36 = "DONE";
salary.lastUpdateUserId = request.user.sub;
salary.lastUpdateFullName = request.user.name;
salary.lastUpdatedAt = new Date();
await this.salaryProfileEmployeeRepository.save(salary, { data: request });
setLogDataDiff(request, { before, after: salary });
});
} }
return null;
}), }),
); );
return new HttpSuccess(); return result.filter(Boolean);
} }
/** /**
@ -9417,8 +9623,7 @@ export class ReportController extends Controller {
body: { body: {
refIds: { refIds: {
refId: string; refId: string;
// commandAffectDate: Date | null;//เก่า commandDateAffect: Date | null;
commandDateAffect: Date | null; //ใหม่ (ปรับตาม rabbitMQ ORG)
commandDateSign?: Date | null; commandDateSign?: Date | null;
commandNo: string | null; commandNo: string | null;
commandYear: number | null; commandYear: number | null;
@ -9438,17 +9643,79 @@ export class ReportController extends Controller {
}, },
@Request() request: RequestWithUser, @Request() request: RequestWithUser,
) { ) {
await Promise.all( // ═══════════════════════════════════════════════════════════════
body.refIds.map(async (v) => { // old circle flow (เก็บไว้อ้างอิง — ลบการใช้งานจริงออกแล้ว)
const salary = await this.salaryProfileEmployeeRepository.findOne({ // ═══════════════════════════════════════════════════════════════
where: { // await Promise.all(
id: v.refId, // body.refIds.map(async (v) => {
}, // const salary = await this.salaryProfileEmployeeRepository.findOne({
}); // where: { id: v.refId },
// });
// if (salary != null) {
// await new CallAPI()
// .PostData(request, "/org/profile-employee/salary/update", {
// profileEmployeeId: salary.profileId,
// commandDateAffect: v.commandDateAffect,
// commandDateSign: v.commandDateSign,
// amount: v.amount,
// amountSpecial: v.amountSpecial,
// positionSalaryAmount: v.positionSalaryAmount,
// mouthSalaryAmount: v.mouthSalaryAmount,
// posNo: salary.posMasterNo != null ? salary.posMasterNo.toString() : null,
// posNoAbb: salary.orgShortName,
// positionName: salary.position,
// positionType: salary.posType,
// positionLevel:
// (salary.posTypeShort != null ? salary.posTypeShort + " " : "") +
// (salary.posLevel != null ? salary.posLevel.toString() : ""),
// remark: v.remark,
// orgRoot: salary.root,
// orgChild1: salary.child1,
// orgChild2: salary.child2,
// orgChild3: salary.child3,
// orgChild4: salary.child4,
// commandCode: v.commandCode,
// commandName: v.commandName,
// commandNo: v.commandNo,
// commandYear: v.commandYear,
// commandId: v.commandId,
// salaryLevel:
// salary.salaryLevel && salary.salaryLevelNew
// ? salary.salaryLevelNew
// : salary.salaryLevel,
// group: salary.groupNew ?? salary.group,
// })
// .then(async () => {
// const before = null;
// salary.status37 = "DONE";
// salary.lastUpdateUserId = request.user.sub;
// salary.lastUpdateFullName = request.user.name;
// salary.lastUpdatedAt = new Date();
// await this.salaryProfileEmployeeRepository.save(salary, { data: request });
// setLogDataDiff(request, { before, after: salary });
// });
// }
// }),
// );
// return new HttpSuccess();
// ═══════════════════════════════════════════════════════════════
// new linear flow
// ═══════════════════════════════════════════════════════════════
const result = await Promise.all(
body.refIds.map(async (v) => {
const salary = await this.salaryProfileEmployeeRepository.findOne({ where: { id: v.refId } });
if (salary != null) { if (salary != null) {
await new CallAPI() // 1) set status37 = DONE (ย้ายขึ้นมาทำก่อนเลย ไม่ต้องรอ org ตอบกลับ)
.PostData(request, "/org/profile-employee/salary/update", { salary.status37 = "DONE";
salary.lastUpdateUserId = request.user.sub;
salary.lastUpdateFullName = request.user.name;
salary.lastUpdatedAt = new Date();
await this.salaryProfileEmployeeRepository.save(salary, { data: request });
setLogDataDiff(request, { before: null, after: salary });
// 2) return ข้อมูลที่ org ต้องการสร้าง ProfileSalary (shape เดียวกับที่เคย PostData)
return {
profileEmployeeId: salary.profileId, profileEmployeeId: salary.profileId,
commandDateAffect: v.commandDateAffect, commandDateAffect: v.commandDateAffect,
commandDateSign: v.commandDateSign, commandDateSign: v.commandDateSign,
@ -9475,24 +9742,14 @@ export class ReportController extends Controller {
commandYear: v.commandYear, commandYear: v.commandYear,
commandId: v.commandId, commandId: v.commandId,
salaryLevel: salaryLevel:
salary.salaryLevel && salary.salaryLevelNew salary.salaryLevel && salary.salaryLevelNew ? salary.salaryLevelNew : salary.salaryLevel,
? salary.salaryLevelNew
: salary.salaryLevel,
group: salary.groupNew ?? salary.group, group: salary.groupNew ?? salary.group,
}) };
.then(async () => {
const before = null;
salary.status37 = "DONE";
salary.lastUpdateUserId = request.user.sub;
salary.lastUpdateFullName = request.user.name;
salary.lastUpdatedAt = new Date();
await this.salaryProfileEmployeeRepository.save(salary, { data: request });
setLogDataDiff(request, { before, after: salary });
});
} }
return null;
}), }),
); );
return new HttpSuccess(); return result.filter(Boolean);
} }
/** /**