import data

This commit is contained in:
mamoss 2025-06-27 14:38:07 +07:00
parent dda4488409
commit eb9ca4f6ea

View file

@ -4765,18 +4765,25 @@ export class ImportDataController extends Controller {
.orderBy("profileSalary.commandDateAffect", "ASC") .orderBy("profileSalary.commandDateAffect", "ASC")
.addOrderBy("profileSalary.order", "ASC") .addOrderBy("profileSalary.order", "ASC")
.getMany(); .getMany();
// const _profiles = await this.salaryTempRepo
// .createQueryBuilder("profileSalaryTemp")
// .select("profileSalaryTemp.profileId", "profileId")
// .where("profileSalaryTemp.createdAt > :date", { date: "2025-06-24" })
// .groupBy("profileSalaryTemp.profileId")
// .getRawMany();
const profiles = await this.profileRepo.find({ const profiles = await this.profileRepo.find({
where: { where: {
id: In(_profiles.map((x) => x.id)), id: In(_profiles.map((x) => x.id)),
profileSalary: { isEntry: true }, // profileSalary: { isEntry: Not(true) },
statusCheckEdit: Not("EDITED"), statusCheckEdit: Not("EDITED"),
}, },
order: { profileSalary: { commandDateAffect: "ASC", order: "ASC" } }, order: { profileSalary: { commandDateAffect: "ASC", order: "ASC" } },
relations: ["profileSalary"], relations: ["profileSalary"],
}); });
// console.log(profiles.lengthisDelete) console.log(profiles.length);
for await (const item of profiles) { for await (const item of profiles) {
console.log(item.id);
// 2. จัดกลุ่มข้อมูลตามวันที่คำสั่งมีผล // 2. จัดกลุ่มข้อมูลตามวันที่คำสั่งมีผล
const groupedByDate = this.groupOrdersByDate(item.profileSalary); const groupedByDate = this.groupOrdersByDate(item.profileSalary);
// 3. ประมวลผลแต่ละกลุ่ม // 3. ประมวลผลแต่ละกลุ่ม
@ -4998,7 +5005,7 @@ export class ImportDataController extends Controller {
// "c9639f3b-26d0-47fc-a53d-1a0e4926697e", // "c9639f3b-26d0-47fc-a53d-1a0e4926697e",
// "e6d40cd6-c77b-4229-8e8d-a6df3f83394b", // "e6d40cd6-c77b-4229-8e8d-a6df3f83394b",
// ]), // ]),
isEntry: true, // isEntry: true,
}, },
relations: ["profile"], relations: ["profile"],
}); });
@ -5023,7 +5030,7 @@ export class ImportDataController extends Controller {
// ฟังก์ชันจัดกลุ่มตามวันที่ // ฟังก์ชันจัดกลุ่มตามวันที่
groupOrdersByDate(orders: ProfileSalary[]) { groupOrdersByDate(orders: ProfileSalary[]) {
return orders.reduce((groups: any, order) => { return orders.reduce((groups: any, order) => {
const date = order.commandDateAffect.toDateString(); // เปลี่ยนชื่อฟิลด์ตามจริง const date = order?.commandDateAffect?.toDateString() || ""; // เปลี่ยนชื่อฟิลด์ตามจริง
if (!groups[date]) { if (!groups[date]) {
groups[date] = []; groups[date] = [];
} }