แก้ไขค้นหา issue #848, #850

This commit is contained in:
Bright 2024-12-12 11:18:58 +07:00
parent 992a48b787
commit 38844e1519
2 changed files with 185 additions and 64 deletions

View file

@ -6372,7 +6372,9 @@ export class OrganizationController extends Controller {
orgRoot.orgRootCode + orgRoot.orgRootCode +
orgChild1.orgChild1Code + orgChild1.orgChild1Code +
" " + " " +
orgChild1.orgChild1ShortName, orgChild1.orgChild1ShortName +
"/" +
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
totalPosition: await this.posMasterRepository.count({ totalPosition: await this.posMasterRepository.count({
where: { orgRevisionId: orgRoot.orgRevisionId, orgChild1Id: orgChild1.id }, where: { orgRevisionId: orgRoot.orgRevisionId, orgChild1Id: orgChild1.id },
}), }),
@ -6487,7 +6489,16 @@ export class OrganizationController extends Controller {
orgRoot.orgRootCode + orgRoot.orgRootCode +
orgChild2.orgChild2Code + orgChild2.orgChild2Code +
" " + " " +
orgChild2.orgChild2ShortName, orgChild2.orgChild2ShortName +
"/" +
orgChild1.orgChild1Name +
" " +
orgRoot.orgRootCode +
orgChild1.orgChild1Code +
" " +
orgChild1.orgChild1ShortName +
"/" +
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
totalPosition: await this.posMasterRepository.count({ totalPosition: await this.posMasterRepository.count({
where: { where: {
orgRevisionId: orgRoot.orgRevisionId, orgRevisionId: orgRoot.orgRevisionId,
@ -6605,7 +6616,23 @@ export class OrganizationController extends Controller {
orgRoot.orgRootCode + orgRoot.orgRootCode +
orgChild3.orgChild3Code + orgChild3.orgChild3Code +
" " + " " +
orgChild3.orgChild3ShortName, orgChild3.orgChild3ShortName +
"/" +
orgChild2.orgChild2Name +
" " +
orgRoot.orgRootCode +
orgChild2.orgChild2Code +
" " +
orgChild2.orgChild2ShortName +
"/" +
orgChild1.orgChild1Name +
" " +
orgRoot.orgRootCode +
orgChild1.orgChild1Code +
" " +
orgChild1.orgChild1ShortName +
"/" +
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
totalPosition: await this.posMasterRepository.count({ totalPosition: await this.posMasterRepository.count({
where: { where: {
orgRevisionId: orgRoot.orgRevisionId, orgRevisionId: orgRoot.orgRevisionId,
@ -6723,7 +6750,30 @@ export class OrganizationController extends Controller {
orgRoot.orgRootCode + orgRoot.orgRootCode +
orgChild4.orgChild4Code + orgChild4.orgChild4Code +
" " + " " +
orgChild4.orgChild4ShortName, orgChild4.orgChild4ShortName +
"/" +
orgChild3.orgChild3Name +
" " +
orgRoot.orgRootCode +
orgChild3.orgChild3Code +
" " +
orgChild3.orgChild3ShortName +
"/" +
orgChild2.orgChild2Name +
" " +
orgRoot.orgRootCode +
orgChild2.orgChild2Code +
" " +
orgChild2.orgChild2ShortName +
"/" +
orgChild1.orgChild1Name +
" " +
orgRoot.orgRootCode +
orgChild1.orgChild1Code +
" " +
orgChild1.orgChild1ShortName +
"/" +
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
totalPosition: await this.posMasterRepository.count({ totalPosition: await this.posMasterRepository.count({
where: { where: {
orgRevisionId: orgRoot.orgRevisionId, orgRevisionId: orgRoot.orgRevisionId,

View file

@ -4953,6 +4953,7 @@ export class PositionController extends Controller {
(masterId.length > 0 (masterId.length > 0
? { id: In(masterId) } ? { id: In(masterId) }
: { posMasterNo: Like(`%${body.keyword}%`) })), : { posMasterNo: Like(`%${body.keyword}%`) })),
current_holderId: IsNull(),
}, },
]; ];
let [posMaster, total] = await AppDataSource.getRepository(PosMaster) let [posMaster, total] = await AppDataSource.getRepository(PosMaster)
@ -4962,11 +4963,14 @@ export class PositionController extends Controller {
.leftJoinAndSelect("posMaster.orgChild2", "orgChild2") .leftJoinAndSelect("posMaster.orgChild2", "orgChild2")
.leftJoinAndSelect("posMaster.orgChild3", "orgChild3") .leftJoinAndSelect("posMaster.orgChild3", "orgChild3")
.leftJoinAndSelect("posMaster.orgChild4", "orgChild4") .leftJoinAndSelect("posMaster.orgChild4", "orgChild4")
.leftJoinAndSelect("posMaster.orgRevision", "orgRevision")
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
.leftJoinAndSelect("current_holder.posType", "posType")
.leftJoinAndSelect("current_holder.posLevel", "posLevel")
.where(conditions) .where(conditions)
.andWhere({ .orWhere(
current_holderId: IsNull(), new Brackets((qb) => {
}) qb.andWhere(
.andWhere(
_data.root != undefined && _data.root != null _data.root != undefined && _data.root != null
? _data.root[0] != null ? _data.root[0] != null
? `posMaster.orgRootId IN (:...root)` ? `posMaster.orgRootId IN (:...root)`
@ -4976,7 +4980,12 @@ export class PositionController extends Controller {
root: _data.root, root: _data.root,
}, },
) )
.andWhere( .andWhere(conditions)
}),
)
.orWhere(
new Brackets((qb) => {
qb.andWhere(
_data.child1 != undefined && _data.child1 != null _data.child1 != undefined && _data.child1 != null
? _data.child1[0] != null ? _data.child1[0] != null
? `posMaster.orgChild1Id IN (:...child1)` ? `posMaster.orgChild1Id IN (:...child1)`
@ -4986,7 +4995,12 @@ export class PositionController extends Controller {
child1: _data.child1, child1: _data.child1,
}, },
) )
.andWhere( .andWhere(conditions)
}),
)
.orWhere(
new Brackets((qb) => {
qb.andWhere(
_data.child2 != undefined && _data.child2 != null _data.child2 != undefined && _data.child2 != null
? _data.child2[0] != null ? _data.child2[0] != null
? `posMaster.orgChild2Id IN (:...child2)` ? `posMaster.orgChild2Id IN (:...child2)`
@ -4996,7 +5010,12 @@ export class PositionController extends Controller {
child2: _data.child2, child2: _data.child2,
}, },
) )
.andWhere( .andWhere(conditions)
}),
)
.orWhere(
new Brackets((qb) => {
qb.andWhere(
_data.child3 != undefined && _data.child3 != null _data.child3 != undefined && _data.child3 != null
? _data.child3[0] != null ? _data.child3[0] != null
? `posMaster.orgChild3Id IN (:...child3)` ? `posMaster.orgChild3Id IN (:...child3)`
@ -5006,7 +5025,12 @@ export class PositionController extends Controller {
child3: _data.child3, child3: _data.child3,
}, },
) )
.andWhere( .andWhere(conditions)
}),
)
.orWhere(
new Brackets((qb) => {
qb.andWhere(
_data.child4 != undefined && _data.child4 != null _data.child4 != undefined && _data.child4 != null
? _data.child4[0] != null ? _data.child4[0] != null
? `posMaster.orgChild4Id IN (:...child4)` ? `posMaster.orgChild4Id IN (:...child4)`
@ -5016,13 +5040,60 @@ export class PositionController extends Controller {
child4: _data.child4, child4: _data.child4,
}, },
) )
.andWhere( .andWhere(conditions)
}),
)
.orWhere(
new Brackets((qb) => {
qb.andWhere(
body.keyword != null && body.keyword != ""
? `current_holder.posType LIKE :keyword`
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.andWhere(conditions)
}),
)
.orWhere(
new Brackets((qb) => {
qb.andWhere(
body.keyword != null && body.keyword != ""
? `current_holder.posLevel LIKE :keyword`
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.andWhere(conditions)
}),
)
.orWhere(
new Brackets((qb) => {
qb.andWhere(
body.keyword != null && body.keyword != ""
? `current_holder.position LIKE :keyword`
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.andWhere(conditions)
}),
)
.orWhere(
new Brackets((qb) => {
qb.andWhere(
body.keyword != null && body.keyword != "" body.keyword != null && body.keyword != ""
? body.isAll == false ? body.isAll == false
? searchShortName ? 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}%'` : `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", : "1=1",
) )
.andWhere(conditions)
}),
)
.orderBy("posMaster.posMasterOrder", "ASC") .orderBy("posMaster.posMasterOrder", "ASC")
.skip((body.page - 1) * body.pageSize) .skip((body.page - 1) * body.pageSize)
.take(body.pageSize) .take(body.pageSize)