แก้ไขค้นหา 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 +
orgChild1.orgChild1Code +
" " +
orgChild1.orgChild1ShortName,
orgChild1.orgChild1ShortName +
"/" +
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
totalPosition: await this.posMasterRepository.count({
where: { orgRevisionId: orgRoot.orgRevisionId, orgChild1Id: orgChild1.id },
}),
@ -6487,7 +6489,16 @@ export class OrganizationController extends Controller {
orgRoot.orgRootCode +
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({
where: {
orgRevisionId: orgRoot.orgRevisionId,
@ -6599,13 +6610,29 @@ export class OrganizationController extends Controller {
orgRevisionId: orgRoot.orgRevisionId,
orgRootName: orgRoot.orgRootName,
responsibility: orgChild3.responsibility,
labelName:
orgChild3.orgChild3Name +
" " +
orgRoot.orgRootCode +
orgChild3.orgChild3Code +
" " +
orgChild3.orgChild3ShortName,
labelName:
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({
where: {
orgRevisionId: orgRoot.orgRevisionId,
@ -6723,7 +6750,30 @@ export class OrganizationController extends Controller {
orgRoot.orgRootCode +
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({
where: {
orgRevisionId: orgRoot.orgRevisionId,

View file

@ -4953,6 +4953,7 @@ export class PositionController extends Controller {
(masterId.length > 0
? { id: In(masterId) }
: { posMasterNo: Like(`%${body.keyword}%`) })),
current_holderId: IsNull(),
},
];
let [posMaster, total] = await AppDataSource.getRepository(PosMaster)
@ -4962,66 +4963,136 @@ export class PositionController extends Controller {
.leftJoinAndSelect("posMaster.orgChild2", "orgChild2")
.leftJoinAndSelect("posMaster.orgChild3", "orgChild3")
.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)
.andWhere({
current_holderId: IsNull(),
})
.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(
_data.root != undefined && _data.root != null
? _data.root[0] != null
? `posMaster.orgRootId IN (:...root)`
: `posMaster.orgRootId is null`
: "1=1",
{
root: _data.root,
},
)
.andWhere(conditions)
}),
)
.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(
_data.child1 != undefined && _data.child1 != null
? _data.child1[0] != null
? `posMaster.orgChild1Id IN (:...child1)`
: `posMaster.orgChild1Id is null`
: "1=1",
{
child1: _data.child1,
},
)
.andWhere(conditions)
}),
)
.andWhere(
_data.child2 != undefined && _data.child2 != null
? _data.child2[0] != null
? `posMaster.orgChild2Id IN (:...child2)`
: `posMaster.orgChild2Id is null`
: "1=1",
{
child2: _data.child2,
},
.orWhere(
new Brackets((qb) => {
qb.andWhere(
_data.child2 != undefined && _data.child2 != null
? _data.child2[0] != null
? `posMaster.orgChild2Id IN (:...child2)`
: `posMaster.orgChild2Id is null`
: "1=1",
{
child2: _data.child2,
},
)
.andWhere(conditions)
}),
)
.andWhere(
_data.child3 != undefined && _data.child3 != null
? _data.child3[0] != null
? `posMaster.orgChild3Id IN (:...child3)`
: `posMaster.orgChild3Id is null`
: "1=1",
{
child3: _data.child3,
},
.orWhere(
new Brackets((qb) => {
qb.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(conditions)
}),
)
.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(
_data.child4 != undefined && _data.child4 != null
? _data.child4[0] != null
? `posMaster.orgChild4Id IN (:...child4)`
: `posMaster.orgChild4Id is null`
: "1=1",
{
child4: _data.child4,
},
)
.andWhere(conditions)
}),
)
.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",
.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.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(conditions)
}),
)
.orderBy("posMaster.posMasterOrder", "ASC")
.skip((body.page - 1) * body.pageSize)