optimize sort #2260
All checks were successful
Build & Deploy on Dev / build (push) Successful in 52s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 52s
This commit is contained in:
parent
f2ab1ec91e
commit
47f7f4d55e
1 changed files with 166 additions and 67 deletions
|
|
@ -7149,75 +7149,174 @@ export class OrganizationController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Get("root/search/sort")
|
@Get("root/search/sort")
|
||||||
async searchSortRootLevelType(@Request() request: RequestWithUser) {
|
async searchSortRootLevelType(@Request() request: RequestWithUser) {
|
||||||
const root1 = await this.orgRootRepository.find({
|
// const root1 = await this.orgRootRepository.find({
|
||||||
where: {
|
// where: {
|
||||||
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
|
// orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
|
||||||
DEPARTMENT_CODE: Not("50"),
|
// DEPARTMENT_CODE: Not("50"),
|
||||||
},
|
// },
|
||||||
order: { isDeputy: "DESC", orgRootOrder: "ASC" },
|
// order: { isDeputy: "DESC", orgRootOrder: "ASC" },
|
||||||
select: ["orgRootName"],
|
// select: ["orgRootName"],
|
||||||
});
|
// });
|
||||||
const root2 = await this.orgRootRepository.find({
|
// const root2 = await this.orgRootRepository.find({
|
||||||
where: {
|
// where: {
|
||||||
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
|
// orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
|
||||||
DEPARTMENT_CODE: "50",
|
// DEPARTMENT_CODE: "50",
|
||||||
},
|
// },
|
||||||
order: { orgRootName: "ASC" },
|
// order: { orgRootName: "ASC" },
|
||||||
select: ["orgRootName"],
|
// select: ["orgRootName"],
|
||||||
});
|
// });
|
||||||
const root = [...root1, ...root2];
|
// const root = [...root1, ...root2];
|
||||||
|
|
||||||
|
// const child1 = await this.child1Repository.find({
|
||||||
|
// where: {
|
||||||
|
// orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
|
||||||
|
// },
|
||||||
|
// order: { orgChild1Order: "ASC" },
|
||||||
|
// select: ["orgChild1Name"],
|
||||||
|
// });
|
||||||
|
// const child2 = await this.child2Repository.find({
|
||||||
|
// where: {
|
||||||
|
// orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
|
||||||
|
// },
|
||||||
|
// order: { orgChild2Order: "ASC" },
|
||||||
|
// select: ["orgChild2Name"],
|
||||||
|
// });
|
||||||
|
// const child3 = await this.child3Repository.find({
|
||||||
|
// where: {
|
||||||
|
// orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
|
||||||
|
// },
|
||||||
|
// order: { orgChild3Order: "ASC" },
|
||||||
|
// select: ["orgChild3Name"],
|
||||||
|
// });
|
||||||
|
// const child4 = await this.child4Repository.find({
|
||||||
|
// where: {
|
||||||
|
// orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
|
||||||
|
// },
|
||||||
|
// order: { orgChild4Order: "ASC" },
|
||||||
|
// select: ["orgChild4Name"],
|
||||||
|
// });
|
||||||
|
// const hospital = await this.child1Repository.find({
|
||||||
|
// where: [
|
||||||
|
// {
|
||||||
|
// orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
|
||||||
|
// orgRoot: { isDeputy: true },
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
|
||||||
|
// orgChild1RankSub: "HOSPITAL",
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
// select: ["orgChild1Name"],
|
||||||
|
// });
|
||||||
|
// const posType = await this.posTypeRepository.find({
|
||||||
|
// order: { posTypeRank: "DESC" },
|
||||||
|
// select: ["posTypeName"],
|
||||||
|
// });
|
||||||
|
// const posLevel = await this.posLevelRepository.find({
|
||||||
|
// order: { posLevelRank: "DESC" },
|
||||||
|
// select: ["posLevelName"],
|
||||||
|
// });
|
||||||
|
|
||||||
|
const [
|
||||||
|
roots,
|
||||||
|
child1,
|
||||||
|
child2,
|
||||||
|
child3,
|
||||||
|
child4,
|
||||||
|
hospital,
|
||||||
|
posType,
|
||||||
|
posLevel,
|
||||||
|
] = await Promise.all([
|
||||||
|
|
||||||
|
// ===== ROOT =====
|
||||||
|
this.orgRootRepository
|
||||||
|
.createQueryBuilder("root")
|
||||||
|
.innerJoin("root.orgRevision", "rev")
|
||||||
|
.select([
|
||||||
|
"root.orgRootName AS orgRootName",
|
||||||
|
])
|
||||||
|
.where("rev.orgRevisionIsDraft = false")
|
||||||
|
.andWhere("rev.orgRevisionIsCurrent = true")
|
||||||
|
.orderBy(
|
||||||
|
"CASE WHEN root.DEPARTMENT_CODE = '50' THEN 1 ELSE 0 END",
|
||||||
|
"ASC",
|
||||||
|
)
|
||||||
|
.addOrderBy("root.isDeputy", "DESC")
|
||||||
|
.addOrderBy("root.orgRootOrder", "ASC")
|
||||||
|
.addOrderBy("root.orgRootName", "ASC")
|
||||||
|
.getRawMany(),
|
||||||
|
|
||||||
|
// ===== CHILD 1 =====
|
||||||
|
this.child1Repository
|
||||||
|
.createQueryBuilder("c1")
|
||||||
|
.innerJoin("c1.orgRevision", "rev")
|
||||||
|
.select("c1.orgChild1Name", "orgChild1Name")
|
||||||
|
.where("rev.orgRevisionIsDraft = false")
|
||||||
|
.andWhere("rev.orgRevisionIsCurrent = true")
|
||||||
|
.orderBy("c1.orgChild1Order", "ASC")
|
||||||
|
.getRawMany(),
|
||||||
|
|
||||||
|
// ===== CHILD 2 =====
|
||||||
|
this.child2Repository
|
||||||
|
.createQueryBuilder("c2")
|
||||||
|
.innerJoin("c2.orgRevision", "rev")
|
||||||
|
.select("c2.orgChild2Name", "orgChild2Name")
|
||||||
|
.where("rev.orgRevisionIsDraft = false")
|
||||||
|
.andWhere("rev.orgRevisionIsCurrent = true")
|
||||||
|
.orderBy("c2.orgChild2Order", "ASC")
|
||||||
|
.getRawMany(),
|
||||||
|
|
||||||
|
// ===== CHILD 3 =====
|
||||||
|
this.child3Repository
|
||||||
|
.createQueryBuilder("c3")
|
||||||
|
.innerJoin("c3.orgRevision", "rev")
|
||||||
|
.select("c3.orgChild3Name", "orgChild3Name")
|
||||||
|
.where("rev.orgRevisionIsDraft = false")
|
||||||
|
.andWhere("rev.orgRevisionIsCurrent = true")
|
||||||
|
.orderBy("c3.orgChild3Order", "ASC")
|
||||||
|
.getRawMany(),
|
||||||
|
|
||||||
|
// ===== CHILD 4 =====
|
||||||
|
this.child4Repository
|
||||||
|
.createQueryBuilder("c4")
|
||||||
|
.innerJoin("c4.orgRevision", "rev")
|
||||||
|
.select("c4.orgChild4Name", "orgChild4Name")
|
||||||
|
.where("rev.orgRevisionIsDraft = false")
|
||||||
|
.andWhere("rev.orgRevisionIsCurrent = true")
|
||||||
|
.orderBy("c4.orgChild4Order", "ASC")
|
||||||
|
.getRawMany(),
|
||||||
|
|
||||||
|
// ===== HOSPITAL =====
|
||||||
|
this.child1Repository
|
||||||
|
.createQueryBuilder("c1")
|
||||||
|
.innerJoin("c1.orgRevision", "rev")
|
||||||
|
.leftJoin("c1.orgRoot", "root")
|
||||||
|
.select("c1.orgChild1Name", "orgChild1Name")
|
||||||
|
.where("rev.orgRevisionIsDraft = false")
|
||||||
|
.andWhere("rev.orgRevisionIsCurrent = true")
|
||||||
|
.andWhere(
|
||||||
|
"(root.isDeputy = true OR c1.orgChild1RankSub = :rank)",
|
||||||
|
{ rank: "HOSPITAL" },
|
||||||
|
)
|
||||||
|
.getRawMany(),
|
||||||
|
|
||||||
|
// ===== POSITION TYPE =====
|
||||||
|
this.posTypeRepository
|
||||||
|
.createQueryBuilder("pt")
|
||||||
|
.select("pt.posTypeName", "posTypeName")
|
||||||
|
.orderBy("pt.posTypeRank", "DESC")
|
||||||
|
.getRawMany(),
|
||||||
|
|
||||||
|
// ===== POSITION LEVEL =====
|
||||||
|
this.posLevelRepository
|
||||||
|
.createQueryBuilder("pl")
|
||||||
|
.select("pl.posLevelName", "posLevelName")
|
||||||
|
.orderBy("pl.posLevelRank", "DESC")
|
||||||
|
.getRawMany(),
|
||||||
|
]);
|
||||||
|
|
||||||
const child1 = await this.child1Repository.find({
|
|
||||||
where: {
|
|
||||||
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
|
|
||||||
},
|
|
||||||
order: { orgChild1Order: "ASC" },
|
|
||||||
select: ["orgChild1Name"],
|
|
||||||
});
|
|
||||||
const child2 = await this.child2Repository.find({
|
|
||||||
where: {
|
|
||||||
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
|
|
||||||
},
|
|
||||||
order: { orgChild2Order: "ASC" },
|
|
||||||
select: ["orgChild2Name"],
|
|
||||||
});
|
|
||||||
const child3 = await this.child3Repository.find({
|
|
||||||
where: {
|
|
||||||
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
|
|
||||||
},
|
|
||||||
order: { orgChild3Order: "ASC" },
|
|
||||||
select: ["orgChild3Name"],
|
|
||||||
});
|
|
||||||
const child4 = await this.child4Repository.find({
|
|
||||||
where: {
|
|
||||||
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
|
|
||||||
},
|
|
||||||
order: { orgChild4Order: "ASC" },
|
|
||||||
select: ["orgChild4Name"],
|
|
||||||
});
|
|
||||||
const hospital = await this.child1Repository.find({
|
|
||||||
where: [
|
|
||||||
{
|
|
||||||
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
|
|
||||||
orgRoot: { isDeputy: true },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
orgRevision: { orgRevisionIsDraft: false, orgRevisionIsCurrent: true },
|
|
||||||
orgChild1RankSub: "HOSPITAL",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
select: ["orgChild1Name"],
|
|
||||||
});
|
|
||||||
const posType = await this.posTypeRepository.find({
|
|
||||||
order: { posTypeRank: "DESC" },
|
|
||||||
select: ["posTypeName"],
|
|
||||||
});
|
|
||||||
const posLevel = await this.posLevelRepository.find({
|
|
||||||
order: { posLevelRank: "DESC" },
|
|
||||||
select: ["posLevelName"],
|
|
||||||
});
|
|
||||||
return new HttpSuccess({
|
return new HttpSuccess({
|
||||||
root: root.map((x) => x.orgRootName),
|
root: roots.map((x) => x.orgRootName),
|
||||||
child1: child1.map((x) => x.orgChild1Name),
|
child1: child1.map((x) => x.orgChild1Name),
|
||||||
child2: child2.map((x) => x.orgChild2Name),
|
child2: child2.map((x) => x.orgChild2Name),
|
||||||
child3: child3.map((x) => x.orgChild3Name),
|
child3: child3.map((x) => x.orgChild3Name),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue