This commit is contained in:
Adisak 2025-12-15 17:30:33 +07:00
parent e20eb9e936
commit 9c8aae417c
3 changed files with 204 additions and 165 deletions

View file

@ -1021,12 +1021,12 @@ export class EmployeePositionController extends Controller {
let typeCondition: any = {}; let typeCondition: any = {};
let checkChildConditions: any = {}; let checkChildConditions: any = {};
let keywordAsInt: any; let keywordAsInt: any;
let searchShortName = ""; let searchShortName = "1=1";
let searchShortName0 = `CONCAT(orgRoot.orgRootShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; let searchShortName0 = `CONCAT(orgRoot.orgRootShortName," ",posMaster.posMasterNo)`;
let searchShortName1 = `CONCAT(orgChild1.orgChild1ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; let searchShortName1 = `CONCAT(orgChild1.orgChild1ShortName," ",posMaster.posMasterNo)`;
let searchShortName2 = `CONCAT(orgChild2.orgChild2ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; let searchShortName2 = `CONCAT(orgChild2.orgChild2ShortName," ",posMaster.posMasterNo)`;
let searchShortName3 = `CONCAT(orgChild3.orgChild3ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; let searchShortName3 = `CONCAT(orgChild3.orgChild3ShortName," ",posMaster.posMasterNo)`;
let searchShortName4 = `CONCAT(orgChild4.orgChild4ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; let searchShortName4 = `CONCAT(orgChild4.orgChild4ShortName," ",posMaster.posMasterNo)`;
let _data = await new permission().PermissionOrgList(request, "SYS_ORG_EMP"); let _data = await new permission().PermissionOrgList(request, "SYS_ORG_EMP");
if (body.type === 0) { if (body.type === 0) {
typeCondition = { typeCondition = {
@ -1036,7 +1036,7 @@ export class EmployeePositionController extends Controller {
checkChildConditions = { checkChildConditions = {
orgChild1Id: IsNull(), orgChild1Id: IsNull(),
}; };
searchShortName = `CONCAT(orgRoot.orgRootShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; searchShortName = `CONCAT(orgRoot.orgRootShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`;
} else { } else {
} }
} else if (body.type === 1) { } else if (body.type === 1) {
@ -1047,7 +1047,7 @@ export class EmployeePositionController extends Controller {
checkChildConditions = { checkChildConditions = {
orgChild2Id: IsNull(), orgChild2Id: IsNull(),
}; };
searchShortName = `CONCAT(orgChild1.orgChild1ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; searchShortName = `CONCAT(orgChild1.orgChild1ShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`;
} else { } else {
} }
} else if (body.type === 2) { } else if (body.type === 2) {
@ -1058,7 +1058,7 @@ export class EmployeePositionController extends Controller {
checkChildConditions = { checkChildConditions = {
orgChild3Id: IsNull(), orgChild3Id: IsNull(),
}; };
searchShortName = `CONCAT(orgChild2.orgChild2ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; searchShortName = `CONCAT(orgChild2.orgChild2ShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`;
} else { } else {
} }
} else if (body.type === 3) { } else if (body.type === 3) {
@ -1069,14 +1069,14 @@ export class EmployeePositionController extends Controller {
checkChildConditions = { checkChildConditions = {
orgChild4Id: IsNull(), orgChild4Id: IsNull(),
}; };
searchShortName = `CONCAT(orgChild3.orgChild3ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; searchShortName = `CONCAT(orgChild3.orgChild3ShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`;
} else { } else {
} }
} else if (body.type === 4) { } else if (body.type === 4) {
typeCondition = { typeCondition = {
orgChild4Id: body.id, orgChild4Id: body.id,
}; };
searchShortName = `CONCAT(orgChild4.orgChild4ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; searchShortName = `CONCAT(orgChild4.orgChild4ShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`;
} }
let findPosition: any; let findPosition: any;
let masterId = new Array(); let masterId = new Array();
@ -1126,7 +1126,7 @@ export class EmployeePositionController extends Controller {
}, },
]; ];
const [posMaster, total] = await AppDataSource.getRepository(EmployeePosMaster) let query = AppDataSource.getRepository(EmployeePosMaster)
.createQueryBuilder("posMaster") .createQueryBuilder("posMaster")
.leftJoinAndSelect("posMaster.orgRoot", "orgRoot") .leftJoinAndSelect("posMaster.orgRoot", "orgRoot")
.leftJoinAndSelect("posMaster.orgChild1", "orgChild1") .leftJoinAndSelect("posMaster.orgChild1", "orgChild1")
@ -1190,7 +1190,9 @@ export class EmployeePositionController extends Controller {
child4: _data.child4, child4: _data.child4,
}, },
) )
.orWhere(
if (body.keyword != null && body.keyword != "") {
query.orWhere(
new Brackets((qb) => { new Brackets((qb) => {
qb.andWhere( qb.andWhere(
body.keyword != null && body.keyword != "" body.keyword != null && body.keyword != ""
@ -1249,6 +1251,9 @@ export class EmployeePositionController extends Controller {
.andWhere(revisionCondition); .andWhere(revisionCondition);
}), }),
) )
}
let [posMaster, total] = await query
.orderBy("orgRoot.orgRootOrder", "ASC") .orderBy("orgRoot.orgRootOrder", "ASC")
.addOrderBy("orgChild1.orgChild1Order", "ASC") .addOrderBy("orgChild1.orgChild1Order", "ASC")
.addOrderBy("orgChild2.orgChild2Order", "ASC") .addOrderBy("orgChild2.orgChild2Order", "ASC")

View file

@ -769,12 +769,12 @@ export class EmployeeTempPositionController extends Controller {
let typeCondition: any = {}; let typeCondition: any = {};
let checkChildConditions: any = {}; let checkChildConditions: any = {};
let keywordAsInt: any; let keywordAsInt: any;
let searchShortName = ""; let searchShortName = "1=1";
let searchShortName0 = `CONCAT(orgRoot.orgRootShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; let searchShortName0 = `CONCAT(orgRoot.orgRootShortName," ",posMaster.posMasterNo)`;
let searchShortName1 = `CONCAT(orgChild1.orgChild1ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; let searchShortName1 = `CONCAT(orgChild1.orgChild1ShortName," ",posMaster.posMasterNo)`;
let searchShortName2 = `CONCAT(orgChild2.orgChild2ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; let searchShortName2 = `CONCAT(orgChild2.orgChild2ShortName," ",posMaster.posMasterNo)`;
let searchShortName3 = `CONCAT(orgChild3.orgChild3ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; let searchShortName3 = `CONCAT(orgChild3.orgChild3ShortName," ",posMaster.posMasterNo)`;
let searchShortName4 = `CONCAT(orgChild4.orgChild4ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; let searchShortName4 = `CONCAT(orgChild4.orgChild4ShortName," ",posMaster.posMasterNo)`;
let _data = await new permission().PermissionOrgList(request, "SYS_ORG_TEMP"); let _data = await new permission().PermissionOrgList(request, "SYS_ORG_TEMP");
if (body.type === 0) { if (body.type === 0) {
typeCondition = { typeCondition = {
@ -784,7 +784,7 @@ export class EmployeeTempPositionController extends Controller {
checkChildConditions = { checkChildConditions = {
orgChild1Id: IsNull(), orgChild1Id: IsNull(),
}; };
searchShortName = `CONCAT(orgRoot.orgRootShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; searchShortName = `CONCAT(orgRoot.orgRootShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`;
} else { } else {
} }
} else if (body.type === 1) { } else if (body.type === 1) {
@ -795,7 +795,7 @@ export class EmployeeTempPositionController extends Controller {
checkChildConditions = { checkChildConditions = {
orgChild2Id: IsNull(), orgChild2Id: IsNull(),
}; };
searchShortName = `CONCAT(orgChild1.orgChild1ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; searchShortName = `CONCAT(orgChild1.orgChild1ShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`;
} else { } else {
} }
} else if (body.type === 2) { } else if (body.type === 2) {
@ -806,7 +806,7 @@ export class EmployeeTempPositionController extends Controller {
checkChildConditions = { checkChildConditions = {
orgChild3Id: IsNull(), orgChild3Id: IsNull(),
}; };
searchShortName = `CONCAT(orgChild2.orgChild2ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; searchShortName = `CONCAT(orgChild2.orgChild2ShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`;
} else { } else {
} }
} else if (body.type === 3) { } else if (body.type === 3) {
@ -817,14 +817,14 @@ export class EmployeeTempPositionController extends Controller {
checkChildConditions = { checkChildConditions = {
orgChild4Id: IsNull(), orgChild4Id: IsNull(),
}; };
searchShortName = `CONCAT(orgChild3.orgChild3ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; searchShortName = `CONCAT(orgChild3.orgChild3ShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`;
} else { } else {
} }
} else if (body.type === 4) { } else if (body.type === 4) {
typeCondition = { typeCondition = {
orgChild4Id: body.id, orgChild4Id: body.id,
}; };
searchShortName = `CONCAT(orgChild4.orgChild4ShortName," ",posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; searchShortName = `CONCAT(orgChild4.orgChild4ShortName," ",posMaster.posMasterNo) like '%${body.keyword}%'`;
} }
let findPosition: any; let findPosition: any;
let masterId = new Array(); let masterId = new Array();
@ -873,8 +873,7 @@ export class EmployeeTempPositionController extends Controller {
: { posMasterNo: Like(`%${body.keyword}%`) })), : { posMasterNo: Like(`%${body.keyword}%`) })),
}, },
]; ];
let query = AppDataSource.getRepository(EmployeeTempPosMaster)
const [posMaster, total] = await AppDataSource.getRepository(EmployeeTempPosMaster)
.createQueryBuilder("posMaster") .createQueryBuilder("posMaster")
.leftJoinAndSelect("posMaster.orgRoot", "orgRoot") .leftJoinAndSelect("posMaster.orgRoot", "orgRoot")
.leftJoinAndSelect("posMaster.orgChild1", "orgChild1") .leftJoinAndSelect("posMaster.orgChild1", "orgChild1")
@ -938,7 +937,9 @@ export class EmployeeTempPositionController extends Controller {
child4: _data.child4, child4: _data.child4,
}, },
) )
.orWhere(
if (body.keyword != null && body.keyword != "") {
query.orWhere(
new Brackets((qb) => { new Brackets((qb) => {
qb.andWhere( qb.andWhere(
body.keyword != null && body.keyword != "" body.keyword != null && body.keyword != ""
@ -997,6 +998,9 @@ export class EmployeeTempPositionController extends Controller {
.andWhere(revisionCondition); .andWhere(revisionCondition);
}), }),
) )
}
let [posMaster, total] = await query
.orderBy("orgRoot.orgRootOrder", "ASC") .orderBy("orgRoot.orgRootOrder", "ASC")
.addOrderBy("orgChild1.orgChild1Order", "ASC") .addOrderBy("orgChild1.orgChild1Order", "ASC")
.addOrderBy("orgChild2.orgChild2Order", "ASC") .addOrderBy("orgChild2.orgChild2Order", "ASC")

View file

@ -2389,6 +2389,36 @@ export class PositionController extends Controller {
: "1=1", : "1=1",
{ child1: _data.child1 } { child1: _data.child1 }
) )
.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(
_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,
},
)
// .andWhere(checkChildConditions) // .andWhere(checkChildConditions)
// .andWhere(typeCondition) // .andWhere(typeCondition)
// .andWhere(revisionCondition); // .andWhere(revisionCondition);