add edu report2
This commit is contained in:
parent
27f3bc0875
commit
d8ec3b2201
1 changed files with 150 additions and 84 deletions
|
|
@ -3658,17 +3658,26 @@ export class ReportController extends Controller {
|
||||||
if (profileIds.length > 0) {
|
if (profileIds.length > 0) {
|
||||||
educationsData = await this.profileEducationRepository
|
educationsData = await this.profileEducationRepository
|
||||||
.createQueryBuilder("pe")
|
.createQueryBuilder("pe")
|
||||||
.select([
|
.select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level"])
|
||||||
"pe.profileId",
|
|
||||||
"pe.finishDate",
|
|
||||||
"pe.degree",
|
|
||||||
"ROW_NUMBER() OVER (PARTITION BY pe.profileId ORDER BY pe.finishDate DESC) as rn",
|
|
||||||
])
|
|
||||||
.where("pe.profileId IN (:...profileIds)", { profileIds })
|
.where("pe.profileId IN (:...profileIds)", { profileIds })
|
||||||
.getRawMany();
|
.andWhere(
|
||||||
|
`(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN (
|
||||||
// Filter เฉพาะ latest education
|
SELECT pe2.profileId,
|
||||||
educationsData = educationsData.filter((ed: any) => ed.rn === 1);
|
COALESCE(MAX(pe2.finishDate), '1900-01-01'),
|
||||||
|
CASE
|
||||||
|
WHEN MAX(pe2.finishDate) IS NOT NULL THEN
|
||||||
|
(SELECT pe3.level FROM profileEducation pe3
|
||||||
|
WHERE pe3.profileId = pe2.profileId
|
||||||
|
AND pe3.finishDate = MAX(pe2.finishDate) LIMIT 1)
|
||||||
|
ELSE MAX(pe2.level)
|
||||||
|
END
|
||||||
|
FROM profileEducation pe2
|
||||||
|
WHERE pe2.profileId IN (:...profileIds)
|
||||||
|
GROUP BY pe2.profileId
|
||||||
|
)`,
|
||||||
|
{ profileIds },
|
||||||
|
)
|
||||||
|
.getMany();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 5: ดึงข้อมูล Salary ล่าสุดของแต่ละ Profile
|
// Step 5: ดึงข้อมูล Salary ล่าสุดของแต่ละ Profile
|
||||||
|
|
@ -3676,17 +3685,18 @@ export class ReportController extends Controller {
|
||||||
if (profileIds.length > 0) {
|
if (profileIds.length > 0) {
|
||||||
salariesData = await this.profileSalaryRepository
|
salariesData = await this.profileSalaryRepository
|
||||||
.createQueryBuilder("ps")
|
.createQueryBuilder("ps")
|
||||||
.select([
|
.select(["ps.profileId", "ps.commandDateAffect", "ps.amount"])
|
||||||
"ps.profileId",
|
|
||||||
"ps.commandDateAffect",
|
|
||||||
"ps.amount",
|
|
||||||
"ROW_NUMBER() OVER (PARTITION BY ps.profileId ORDER BY ps.commandDateAffect DESC) as rn",
|
|
||||||
])
|
|
||||||
.where("ps.profileId IN (:...profileIds)", { profileIds })
|
.where("ps.profileId IN (:...profileIds)", { profileIds })
|
||||||
.getRawMany();
|
.andWhere(
|
||||||
|
`(ps.profileId, ps.commandDateAffect) IN (
|
||||||
// Filter เฉพาะ latest salary
|
SELECT ps2.profileId, MAX(ps2.commandDateAffect)
|
||||||
salariesData = salariesData.filter((sal: any) => sal.rn === 1);
|
FROM profileSalary ps2
|
||||||
|
WHERE ps2.profileId IN (:...profileIds)
|
||||||
|
GROUP BY ps2.profileId
|
||||||
|
)`,
|
||||||
|
{ profileIds },
|
||||||
|
)
|
||||||
|
.getMany();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 6: ดึงข้อมูล Positions ที่เกี่ยวข้อง
|
// Step 6: ดึงข้อมูล Positions ที่เกี่ยวข้อง
|
||||||
|
|
@ -3832,27 +3842,41 @@ export class ReportController extends Controller {
|
||||||
|
|
||||||
this.profileEducationRepository
|
this.profileEducationRepository
|
||||||
.createQueryBuilder("pe")
|
.createQueryBuilder("pe")
|
||||||
.select([
|
.select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level"])
|
||||||
"pe.profileId",
|
|
||||||
"pe.finishDate",
|
|
||||||
"pe.degree",
|
|
||||||
"ROW_NUMBER() OVER (PARTITION BY pe.profileId ORDER BY pe.finishDate DESC) as rn",
|
|
||||||
])
|
|
||||||
.where("pe.profileId IN (:...child1ProfileIds)", { child1ProfileIds })
|
.where("pe.profileId IN (:...child1ProfileIds)", { child1ProfileIds })
|
||||||
.getRawMany()
|
.andWhere(
|
||||||
.then((data: any[]) => data.filter((ed: any) => ed.rn === 1)),
|
`(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN (
|
||||||
|
SELECT pe2.profileId,
|
||||||
|
COALESCE(MAX(pe2.finishDate), '1900-01-01'),
|
||||||
|
CASE
|
||||||
|
WHEN MAX(pe2.finishDate) IS NOT NULL THEN
|
||||||
|
(SELECT pe3.level FROM profileEducation pe3
|
||||||
|
WHERE pe3.profileId = pe2.profileId
|
||||||
|
AND pe3.finishDate = MAX(pe2.finishDate) LIMIT 1)
|
||||||
|
ELSE MAX(pe2.level)
|
||||||
|
END
|
||||||
|
FROM profileEducation pe2
|
||||||
|
WHERE pe2.profileId IN (:...child1ProfileIds)
|
||||||
|
GROUP BY pe2.profileId
|
||||||
|
)`,
|
||||||
|
{ child1ProfileIds },
|
||||||
|
)
|
||||||
|
.getMany(),
|
||||||
|
|
||||||
this.profileSalaryRepository
|
this.profileSalaryRepository
|
||||||
.createQueryBuilder("ps")
|
.createQueryBuilder("ps")
|
||||||
.select([
|
.select(["ps.profileId", "ps.commandDateAffect", "ps.amount"])
|
||||||
"ps.profileId",
|
|
||||||
"ps.commandDateAffect",
|
|
||||||
"ps.amount",
|
|
||||||
"ROW_NUMBER() OVER (PARTITION BY ps.profileId ORDER BY ps.commandDateAffect DESC) as rn",
|
|
||||||
])
|
|
||||||
.where("ps.profileId IN (:...child1ProfileIds)", { child1ProfileIds })
|
.where("ps.profileId IN (:...child1ProfileIds)", { child1ProfileIds })
|
||||||
.getRawMany()
|
.andWhere(
|
||||||
.then((data: any[]) => data.filter((sal: any) => sal.rn === 1)),
|
`(ps.profileId, ps.commandDateAffect) IN (
|
||||||
|
SELECT ps2.profileId, MAX(ps2.commandDateAffect)
|
||||||
|
FROM profileSalary ps2
|
||||||
|
WHERE ps2.profileId IN (:...child1ProfileIds)
|
||||||
|
GROUP BY ps2.profileId
|
||||||
|
)`,
|
||||||
|
{ child1ProfileIds },
|
||||||
|
)
|
||||||
|
.getMany(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3998,27 +4022,41 @@ export class ReportController extends Controller {
|
||||||
|
|
||||||
this.profileEducationRepository
|
this.profileEducationRepository
|
||||||
.createQueryBuilder("pe")
|
.createQueryBuilder("pe")
|
||||||
.select([
|
.select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level"])
|
||||||
"pe.profileId",
|
|
||||||
"pe.finishDate",
|
|
||||||
"pe.degree",
|
|
||||||
"ROW_NUMBER() OVER (PARTITION BY pe.profileId ORDER BY pe.finishDate DESC) as rn",
|
|
||||||
])
|
|
||||||
.where("pe.profileId IN (:...child2ProfileIds)", { child2ProfileIds })
|
.where("pe.profileId IN (:...child2ProfileIds)", { child2ProfileIds })
|
||||||
.getRawMany()
|
.andWhere(
|
||||||
.then((data: any[]) => data.filter((ed: any) => ed.rn === 1)),
|
`(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN (
|
||||||
|
SELECT pe2.profileId,
|
||||||
|
COALESCE(MAX(pe2.finishDate), '1900-01-01'),
|
||||||
|
CASE
|
||||||
|
WHEN MAX(pe2.finishDate) IS NOT NULL THEN
|
||||||
|
(SELECT pe3.level FROM profileEducation pe3
|
||||||
|
WHERE pe3.profileId = pe2.profileId
|
||||||
|
AND pe3.finishDate = MAX(pe2.finishDate) LIMIT 1)
|
||||||
|
ELSE MAX(pe2.level)
|
||||||
|
END
|
||||||
|
FROM profileEducation pe2
|
||||||
|
WHERE pe2.profileId IN (:...child2ProfileIds)
|
||||||
|
GROUP BY pe2.profileId
|
||||||
|
)`,
|
||||||
|
{ child2ProfileIds },
|
||||||
|
)
|
||||||
|
.getMany(),
|
||||||
|
|
||||||
this.profileSalaryRepository
|
this.profileSalaryRepository
|
||||||
.createQueryBuilder("ps")
|
.createQueryBuilder("ps")
|
||||||
.select([
|
.select(["ps.profileId", "ps.commandDateAffect", "ps.amount"])
|
||||||
"ps.profileId",
|
|
||||||
"ps.commandDateAffect",
|
|
||||||
"ps.amount",
|
|
||||||
"ROW_NUMBER() OVER (PARTITION BY ps.profileId ORDER BY ps.commandDateAffect DESC) as rn",
|
|
||||||
])
|
|
||||||
.where("ps.profileId IN (:...child2ProfileIds)", { child2ProfileIds })
|
.where("ps.profileId IN (:...child2ProfileIds)", { child2ProfileIds })
|
||||||
.getRawMany()
|
.andWhere(
|
||||||
.then((data: any[]) => data.filter((sal: any) => sal.rn === 1)),
|
`(ps.profileId, ps.commandDateAffect) IN (
|
||||||
|
SELECT ps2.profileId, MAX(ps2.commandDateAffect)
|
||||||
|
FROM profileSalary ps2
|
||||||
|
WHERE ps2.profileId IN (:...child2ProfileIds)
|
||||||
|
GROUP BY ps2.profileId
|
||||||
|
)`,
|
||||||
|
{ child2ProfileIds },
|
||||||
|
)
|
||||||
|
.getMany(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4164,27 +4202,41 @@ export class ReportController extends Controller {
|
||||||
|
|
||||||
this.profileEducationRepository
|
this.profileEducationRepository
|
||||||
.createQueryBuilder("pe")
|
.createQueryBuilder("pe")
|
||||||
.select([
|
.select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level"])
|
||||||
"pe.profileId",
|
|
||||||
"pe.finishDate",
|
|
||||||
"pe.degree",
|
|
||||||
"ROW_NUMBER() OVER (PARTITION BY pe.profileId ORDER BY pe.finishDate DESC) as rn",
|
|
||||||
])
|
|
||||||
.where("pe.profileId IN (:...child3ProfileIds)", { child3ProfileIds })
|
.where("pe.profileId IN (:...child3ProfileIds)", { child3ProfileIds })
|
||||||
.getRawMany()
|
.andWhere(
|
||||||
.then((data: any[]) => data.filter((ed: any) => ed.rn === 1)),
|
`(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN (
|
||||||
|
SELECT pe2.profileId,
|
||||||
|
COALESCE(MAX(pe2.finishDate), '1900-01-01'),
|
||||||
|
CASE
|
||||||
|
WHEN MAX(pe2.finishDate) IS NOT NULL THEN
|
||||||
|
(SELECT pe3.level FROM profileEducation pe3
|
||||||
|
WHERE pe3.profileId = pe2.profileId
|
||||||
|
AND pe3.finishDate = MAX(pe2.finishDate) LIMIT 1)
|
||||||
|
ELSE MAX(pe2.level)
|
||||||
|
END
|
||||||
|
FROM profileEducation pe2
|
||||||
|
WHERE pe2.profileId IN (:...child3ProfileIds)
|
||||||
|
GROUP BY pe2.profileId
|
||||||
|
)`,
|
||||||
|
{ child3ProfileIds },
|
||||||
|
)
|
||||||
|
.getMany(),
|
||||||
|
|
||||||
this.profileSalaryRepository
|
this.profileSalaryRepository
|
||||||
.createQueryBuilder("ps")
|
.createQueryBuilder("ps")
|
||||||
.select([
|
.select(["ps.profileId", "ps.commandDateAffect", "ps.amount"])
|
||||||
"ps.profileId",
|
|
||||||
"ps.commandDateAffect",
|
|
||||||
"ps.amount",
|
|
||||||
"ROW_NUMBER() OVER (PARTITION BY ps.profileId ORDER BY ps.commandDateAffect DESC) as rn",
|
|
||||||
])
|
|
||||||
.where("ps.profileId IN (:...child3ProfileIds)", { child3ProfileIds })
|
.where("ps.profileId IN (:...child3ProfileIds)", { child3ProfileIds })
|
||||||
.getRawMany()
|
.andWhere(
|
||||||
.then((data: any[]) => data.filter((sal: any) => sal.rn === 1)),
|
`(ps.profileId, ps.commandDateAffect) IN (
|
||||||
|
SELECT ps2.profileId, MAX(ps2.commandDateAffect)
|
||||||
|
FROM profileSalary ps2
|
||||||
|
WHERE ps2.profileId IN (:...child3ProfileIds)
|
||||||
|
GROUP BY ps2.profileId
|
||||||
|
)`,
|
||||||
|
{ child3ProfileIds },
|
||||||
|
)
|
||||||
|
.getMany(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4328,27 +4380,41 @@ export class ReportController extends Controller {
|
||||||
|
|
||||||
this.profileEducationRepository
|
this.profileEducationRepository
|
||||||
.createQueryBuilder("pe")
|
.createQueryBuilder("pe")
|
||||||
.select([
|
.select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level"])
|
||||||
"pe.profileId",
|
|
||||||
"pe.finishDate",
|
|
||||||
"pe.degree",
|
|
||||||
"ROW_NUMBER() OVER (PARTITION BY pe.profileId ORDER BY pe.finishDate DESC) as rn",
|
|
||||||
])
|
|
||||||
.where("pe.profileId IN (:...child4ProfileIds)", { child4ProfileIds })
|
.where("pe.profileId IN (:...child4ProfileIds)", { child4ProfileIds })
|
||||||
.getRawMany()
|
.andWhere(
|
||||||
.then((data: any[]) => data.filter((ed: any) => ed.rn === 1)),
|
`(pe.profileId, COALESCE(pe.finishDate, '1900-01-01'), pe.level) IN (
|
||||||
|
SELECT pe2.profileId,
|
||||||
|
COALESCE(MAX(pe2.finishDate), '1900-01-01'),
|
||||||
|
CASE
|
||||||
|
WHEN MAX(pe2.finishDate) IS NOT NULL THEN
|
||||||
|
(SELECT pe3.level FROM profileEducation pe3
|
||||||
|
WHERE pe3.profileId = pe2.profileId
|
||||||
|
AND pe3.finishDate = MAX(pe2.finishDate) LIMIT 1)
|
||||||
|
ELSE MAX(pe2.level)
|
||||||
|
END
|
||||||
|
FROM profileEducation pe2
|
||||||
|
WHERE pe2.profileId IN (:...child4ProfileIds)
|
||||||
|
GROUP BY pe2.profileId
|
||||||
|
)`,
|
||||||
|
{ child4ProfileIds },
|
||||||
|
)
|
||||||
|
.getMany(),
|
||||||
|
|
||||||
this.profileSalaryRepository
|
this.profileSalaryRepository
|
||||||
.createQueryBuilder("ps")
|
.createQueryBuilder("ps")
|
||||||
.select([
|
.select(["ps.profileId", "ps.commandDateAffect", "ps.amount"])
|
||||||
"ps.profileId",
|
|
||||||
"ps.commandDateAffect",
|
|
||||||
"ps.amount",
|
|
||||||
"ROW_NUMBER() OVER (PARTITION BY ps.profileId ORDER BY ps.commandDateAffect DESC) as rn",
|
|
||||||
])
|
|
||||||
.where("ps.profileId IN (:...child4ProfileIds)", { child4ProfileIds })
|
.where("ps.profileId IN (:...child4ProfileIds)", { child4ProfileIds })
|
||||||
.getRawMany()
|
.andWhere(
|
||||||
.then((data: any[]) => data.filter((sal: any) => sal.rn === 1)),
|
`(ps.profileId, ps.commandDateAffect) IN (
|
||||||
|
SELECT ps2.profileId, MAX(ps2.commandDateAffect)
|
||||||
|
FROM profileSalary ps2
|
||||||
|
WHERE ps2.profileId IN (:...child4ProfileIds)
|
||||||
|
GROUP BY ps2.profileId
|
||||||
|
)`,
|
||||||
|
{ child4ProfileIds },
|
||||||
|
)
|
||||||
|
.getMany(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue