This commit is contained in:
AdisakKanthawilang 2024-09-16 18:00:44 +07:00
parent 40440ca250
commit 57bffdc10a
2 changed files with 111 additions and 44 deletions

View file

@ -1094,6 +1094,7 @@ export class PositionController extends Controller {
*/
@Post("master/list")
async list(
@Request() request: RequestWithUser,
@Body()
body: {
id: string;
@ -1115,8 +1116,15 @@ export class PositionController extends Controller {
let searchShortName2 = `CONCAT(orgChild2.orgChild2ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`;
let searchShortName3 = `CONCAT(orgChild3.orgChild3ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`;
let searchShortName4 = `CONCAT(orgChild4.orgChild4ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`;
let _data = await new permission().PermissionOrgList(request, "SYS_ORG");
console.log(">>>>>>>>>>", _data);
let _child = 0;
if (_data.child4 && _data.child4.length > 0) _child = 4;
if (_data.child3 && _data.child3.length > 0) _child = 3;
if (_data.child2 && _data.child2.length > 0) _child = 2;
if (_data.child1 && _data.child1.length > 0) _child = 1;
if (body.type === 0) {
console.log("0");
typeCondition = {
orgRootId: body.id,
};
@ -1128,6 +1136,7 @@ export class PositionController extends Controller {
} else {
}
} else if (body.type === 1) {
console.log("1");
typeCondition = {
orgChild1Id: body.id,
};
@ -1139,6 +1148,7 @@ export class PositionController extends Controller {
} else {
}
} else if (body.type === 2) {
console.log("2");
typeCondition = {
orgChild2Id: body.id,
};
@ -1150,6 +1160,7 @@ export class PositionController extends Controller {
} else {
}
} else if (body.type === 3) {
console.log("3");
typeCondition = {
orgChild3Id: body.id,
};
@ -1161,6 +1172,7 @@ export class PositionController extends Controller {
} else {
}
} else if (body.type === 4) {
console.log("4");
typeCondition = {
orgChild4Id: body.id,
};
@ -1222,7 +1234,7 @@ export class PositionController extends Controller {
: { posMasterNo: Like(`%${body.keyword}%`) })),
},
];
let [posMaster, total] = await AppDataSource.getRepository(PosMaster)
.createQueryBuilder("posMaster")
.leftJoinAndSelect("posMaster.orgRoot", "orgRoot")
@ -1234,51 +1246,101 @@ export class PositionController extends Controller {
.leftJoinAndSelect("posMaster.next_holder", "next_holder")
.leftJoinAndSelect("posMaster.orgRevision", "orgRevision")
.where(conditions)
.orWhere(
new Brackets((qb) => {
qb.andWhere(
body.keyword != null && body.keyword != ""
? body.isAll == false
? searchShortName
: `CASE WHEN posMaster.orgChild1 is null THEN ${searchShortName0} WHEN posMaster.orgChild2 is null THEN ${searchShortName1} WHEN posMaster.orgChild3 is null THEN ${searchShortName2} WHEN posMaster.orgChild4 is null THEN ${searchShortName3} ELSE ${searchShortName4} END LIKE '%${body.keyword}%'`
: "1=1",
)
.andWhere(checkChildConditions)
.andWhere(typeCondition)
.andWhere(revisionCondition);
}),
.andWhere(
_data.root != undefined && _data.root != null
? _data.root[0] != null
? `posMaster.orgRootId IN (:...root)`
: `posMaster.orgRootId is null`
: "1=1",
{
root: _data.root,
},
)
.orWhere(
new Brackets((qb) => {
qb.andWhere(
body.keyword != null && body.keyword != ""
? `CONCAT(current_holder.prefix, current_holder.firstName," ",current_holder.lastName) like '%${body.keyword}%'`
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.andWhere(checkChildConditions)
.andWhere(typeCondition)
.andWhere(revisionCondition);
}),
.andWhere(
_data.child1 != undefined && _data.child1 != null
? _data.child1[0] != null
? `posMaster.orgChild1Id IN (:...child1)`
: `posMaster.orgChild1Id is null`
: "1=1",
{
child1: _data.child1,
},
)
.orWhere(
new Brackets((qb) => {
qb.andWhere(
body.keyword != null && body.keyword != ""
? `CASE WHEN orgRevision.orgRevisionIsDraft = true THEN CONCAT(next_holder.prefix, next_holder.firstName,' ', next_holder.lastName) ELSE CONCAT(current_holder.prefix, current_holder.firstName,' ' , current_holder.lastName) END LIKE '%${body.keyword}%'`
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.andWhere(checkChildConditions)
.andWhere(typeCondition)
.andWhere(revisionCondition);
}),
.andWhere(
_data.child2 != undefined && _data.child2 != null
? _data.child2[0] != null
? `posMaster.orgChild2Id IN (:...child2)`
: `posMaster.orgChild2Id is null`
: "1=1",
{
child2: _data.child2,
},
)
.orderBy("posMaster.posMasterOrder", "ASC")
.andWhere(
_data.child3 != undefined && _data.child3 != null
? _data.child3[0] != null
? `posMaster.orgChild3Id IN (:...child3)`
: `posMaster.orgChild3Id is null`
: "1=1",
{
child3: _data.child3,
},
)
.andWhere(
_data.child4 != undefined && _data.child4 != null
? _data.child4[0] != null
? `posMaster.orgChild4Id IN (:...child4)`
: `posMaster.orgChild4Id is null`
: "1=1",
{
child4: _data.child4,
},
)
// .orWhere(
// new Brackets((qb) => {
// qb.andWhere(
// body.keyword != null && body.keyword != ""
// ? body.isAll == false
// ? searchShortName
// : `CASE WHEN posMaster.orgChild1 is null THEN ${searchShortName0} WHEN posMaster.orgChild2 is null THEN ${searchShortName1} WHEN posMaster.orgChild3 is null THEN ${searchShortName2} WHEN posMaster.orgChild4 is null THEN ${searchShortName3} ELSE ${searchShortName4} END LIKE '%${body.keyword}%'`
// : "1=1",
// )
// .andWhere(checkChildConditions)
// .andWhere(typeCondition)
// .andWhere(revisionCondition);
// }),
// )
// .orWhere(
// new Brackets((qb) => {
// qb.andWhere(
// body.keyword != null && body.keyword != ""
// ? `CONCAT(current_holder.prefix, current_holder.firstName," ",current_holder.lastName) like '%${body.keyword}%'`
// : "1=1",
// {
// keyword: `%${body.keyword}%`,
// },
// )
// .andWhere(checkChildConditions)
// .andWhere(typeCondition)
// .andWhere(revisionCondition);
// }),
// )
// .orWhere(
// new Brackets((qb) => {
// qb.andWhere(
// body.keyword != null && body.keyword != ""
// ? `CASE WHEN orgRevision.orgRevisionIsDraft = true THEN CONCAT(next_holder.prefix, next_holder.firstName,' ', next_holder.lastName) ELSE CONCAT(current_holder.prefix, current_holder.firstName,' ' , current_holder.lastName) END LIKE '%${body.keyword}%'`
// : "1=1",
// {
// keyword: `%${body.keyword}%`,
// },
// )
// .andWhere(checkChildConditions)
// .andWhere(typeCondition)
// .andWhere(revisionCondition);
// }),
// )
// .orderBy("posMaster.posMasterOrder", "ASC")
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
.getManyAndCount();

View file

@ -72,6 +72,7 @@ class CheckAuth {
child2: [null],
child3: [null],
child4: [null],
privilege: [null],
};
let node = 4;
if (x.orgChild1Id == null) {
@ -90,6 +91,7 @@ class CheckAuth {
child2: null,
child3: null,
child4: null,
privilege: "ROOT",
};
} else if (privilege == "CHILD") {
data = {
@ -98,6 +100,7 @@ class CheckAuth {
child2: node >= 2 ? [x.orgChild2Id] : null,
child3: node >= 3 ? [x.orgChild3Id] : null,
child4: node >= 4 ? [x.orgChild4Id] : null,
privilege: "CHILD",
};
} else if (privilege == "NORMAL") {
data = {
@ -106,6 +109,7 @@ class CheckAuth {
child2: [x.orgChild2Id],
child3: [x.orgChild3Id],
child4: [x.orgChild4Id],
privilege: "NORMAL",
};
} else if (privilege == "SPECIFIC") {
} else if (privilege == "OWNER") {
@ -115,6 +119,7 @@ class CheckAuth {
child2: null,
child3: null,
child4: null,
privilege: "OWNER",
};
}