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) {
|
||||
educationsData = await this.profileEducationRepository
|
||||
.createQueryBuilder("pe")
|
||||
.select([
|
||||
"pe.profileId",
|
||||
"pe.finishDate",
|
||||
"pe.degree",
|
||||
"ROW_NUMBER() OVER (PARTITION BY pe.profileId ORDER BY pe.finishDate DESC) as rn",
|
||||
])
|
||||
.select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level"])
|
||||
.where("pe.profileId IN (:...profileIds)", { profileIds })
|
||||
.getRawMany();
|
||||
|
||||
// Filter เฉพาะ latest education
|
||||
educationsData = educationsData.filter((ed: any) => ed.rn === 1);
|
||||
.andWhere(
|
||||
`(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 (:...profileIds)
|
||||
GROUP BY pe2.profileId
|
||||
)`,
|
||||
{ profileIds },
|
||||
)
|
||||
.getMany();
|
||||
}
|
||||
|
||||
// Step 5: ดึงข้อมูล Salary ล่าสุดของแต่ละ Profile
|
||||
|
|
@ -3676,17 +3685,18 @@ export class ReportController extends Controller {
|
|||
if (profileIds.length > 0) {
|
||||
salariesData = await this.profileSalaryRepository
|
||||
.createQueryBuilder("ps")
|
||||
.select([
|
||||
"ps.profileId",
|
||||
"ps.commandDateAffect",
|
||||
"ps.amount",
|
||||
"ROW_NUMBER() OVER (PARTITION BY ps.profileId ORDER BY ps.commandDateAffect DESC) as rn",
|
||||
])
|
||||
.select(["ps.profileId", "ps.commandDateAffect", "ps.amount"])
|
||||
.where("ps.profileId IN (:...profileIds)", { profileIds })
|
||||
.getRawMany();
|
||||
|
||||
// Filter เฉพาะ latest salary
|
||||
salariesData = salariesData.filter((sal: any) => sal.rn === 1);
|
||||
.andWhere(
|
||||
`(ps.profileId, ps.commandDateAffect) IN (
|
||||
SELECT ps2.profileId, MAX(ps2.commandDateAffect)
|
||||
FROM profileSalary ps2
|
||||
WHERE ps2.profileId IN (:...profileIds)
|
||||
GROUP BY ps2.profileId
|
||||
)`,
|
||||
{ profileIds },
|
||||
)
|
||||
.getMany();
|
||||
}
|
||||
|
||||
// Step 6: ดึงข้อมูล Positions ที่เกี่ยวข้อง
|
||||
|
|
@ -3832,27 +3842,41 @@ export class ReportController extends Controller {
|
|||
|
||||
this.profileEducationRepository
|
||||
.createQueryBuilder("pe")
|
||||
.select([
|
||||
"pe.profileId",
|
||||
"pe.finishDate",
|
||||
"pe.degree",
|
||||
"ROW_NUMBER() OVER (PARTITION BY pe.profileId ORDER BY pe.finishDate DESC) as rn",
|
||||
])
|
||||
.select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level"])
|
||||
.where("pe.profileId IN (:...child1ProfileIds)", { child1ProfileIds })
|
||||
.getRawMany()
|
||||
.then((data: any[]) => data.filter((ed: any) => ed.rn === 1)),
|
||||
.andWhere(
|
||||
`(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
|
||||
.createQueryBuilder("ps")
|
||||
.select([
|
||||
"ps.profileId",
|
||||
"ps.commandDateAffect",
|
||||
"ps.amount",
|
||||
"ROW_NUMBER() OVER (PARTITION BY ps.profileId ORDER BY ps.commandDateAffect DESC) as rn",
|
||||
])
|
||||
.select(["ps.profileId", "ps.commandDateAffect", "ps.amount"])
|
||||
.where("ps.profileId IN (:...child1ProfileIds)", { child1ProfileIds })
|
||||
.getRawMany()
|
||||
.then((data: any[]) => data.filter((sal: any) => sal.rn === 1)),
|
||||
.andWhere(
|
||||
`(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
|
||||
.createQueryBuilder("pe")
|
||||
.select([
|
||||
"pe.profileId",
|
||||
"pe.finishDate",
|
||||
"pe.degree",
|
||||
"ROW_NUMBER() OVER (PARTITION BY pe.profileId ORDER BY pe.finishDate DESC) as rn",
|
||||
])
|
||||
.select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level"])
|
||||
.where("pe.profileId IN (:...child2ProfileIds)", { child2ProfileIds })
|
||||
.getRawMany()
|
||||
.then((data: any[]) => data.filter((ed: any) => ed.rn === 1)),
|
||||
.andWhere(
|
||||
`(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
|
||||
.createQueryBuilder("ps")
|
||||
.select([
|
||||
"ps.profileId",
|
||||
"ps.commandDateAffect",
|
||||
"ps.amount",
|
||||
"ROW_NUMBER() OVER (PARTITION BY ps.profileId ORDER BY ps.commandDateAffect DESC) as rn",
|
||||
])
|
||||
.select(["ps.profileId", "ps.commandDateAffect", "ps.amount"])
|
||||
.where("ps.profileId IN (:...child2ProfileIds)", { child2ProfileIds })
|
||||
.getRawMany()
|
||||
.then((data: any[]) => data.filter((sal: any) => sal.rn === 1)),
|
||||
.andWhere(
|
||||
`(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
|
||||
.createQueryBuilder("pe")
|
||||
.select([
|
||||
"pe.profileId",
|
||||
"pe.finishDate",
|
||||
"pe.degree",
|
||||
"ROW_NUMBER() OVER (PARTITION BY pe.profileId ORDER BY pe.finishDate DESC) as rn",
|
||||
])
|
||||
.select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level"])
|
||||
.where("pe.profileId IN (:...child3ProfileIds)", { child3ProfileIds })
|
||||
.getRawMany()
|
||||
.then((data: any[]) => data.filter((ed: any) => ed.rn === 1)),
|
||||
.andWhere(
|
||||
`(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
|
||||
.createQueryBuilder("ps")
|
||||
.select([
|
||||
"ps.profileId",
|
||||
"ps.commandDateAffect",
|
||||
"ps.amount",
|
||||
"ROW_NUMBER() OVER (PARTITION BY ps.profileId ORDER BY ps.commandDateAffect DESC) as rn",
|
||||
])
|
||||
.select(["ps.profileId", "ps.commandDateAffect", "ps.amount"])
|
||||
.where("ps.profileId IN (:...child3ProfileIds)", { child3ProfileIds })
|
||||
.getRawMany()
|
||||
.then((data: any[]) => data.filter((sal: any) => sal.rn === 1)),
|
||||
.andWhere(
|
||||
`(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
|
||||
.createQueryBuilder("pe")
|
||||
.select([
|
||||
"pe.profileId",
|
||||
"pe.finishDate",
|
||||
"pe.degree",
|
||||
"ROW_NUMBER() OVER (PARTITION BY pe.profileId ORDER BY pe.finishDate DESC) as rn",
|
||||
])
|
||||
.select(["pe.profileId", "pe.finishDate", "pe.degree", "pe.level"])
|
||||
.where("pe.profileId IN (:...child4ProfileIds)", { child4ProfileIds })
|
||||
.getRawMany()
|
||||
.then((data: any[]) => data.filter((ed: any) => ed.rn === 1)),
|
||||
.andWhere(
|
||||
`(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
|
||||
.createQueryBuilder("ps")
|
||||
.select([
|
||||
"ps.profileId",
|
||||
"ps.commandDateAffect",
|
||||
"ps.amount",
|
||||
"ROW_NUMBER() OVER (PARTITION BY ps.profileId ORDER BY ps.commandDateAffect DESC) as rn",
|
||||
])
|
||||
.select(["ps.profileId", "ps.commandDateAffect", "ps.amount"])
|
||||
.where("ps.profileId IN (:...child4ProfileIds)", { child4ProfileIds })
|
||||
.getRawMany()
|
||||
.then((data: any[]) => data.filter((sal: any) => sal.rn === 1)),
|
||||
.andWhere(
|
||||
`(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