no message
This commit is contained in:
parent
af38addf46
commit
d2974a12ab
1 changed files with 156 additions and 157 deletions
|
|
@ -1695,157 +1695,156 @@ export class PositionController extends Controller {
|
||||||
child4: null,
|
child4: null,
|
||||||
privilege: "OWNER",
|
privilege: "OWNER",
|
||||||
};
|
};
|
||||||
const conditions = [
|
const conditions = [
|
||||||
|
{
|
||||||
|
...checkChildConditions,
|
||||||
|
...typeCondition,
|
||||||
|
...revisionCondition,
|
||||||
|
...(body.keyword &&
|
||||||
|
(masterId.length > 0
|
||||||
|
? { id: In(masterId) }
|
||||||
|
: { posMasterNo: Like(`%${body.keyword}%`) })),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
let [posMaster, total] = await AppDataSource.getRepository(PosMaster)
|
||||||
|
.createQueryBuilder("posMaster")
|
||||||
|
.leftJoinAndSelect("posMaster.orgRoot", "orgRoot")
|
||||||
|
.leftJoinAndSelect("posMaster.orgChild1", "orgChild1")
|
||||||
|
.leftJoinAndSelect("posMaster.orgChild2", "orgChild2")
|
||||||
|
.leftJoinAndSelect("posMaster.orgChild3", "orgChild3")
|
||||||
|
.leftJoinAndSelect("posMaster.orgChild4", "orgChild4")
|
||||||
|
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
|
||||||
|
.leftJoinAndSelect("posMaster.next_holder", "next_holder")
|
||||||
|
.leftJoinAndSelect("posMaster.orgRevision", "orgRevision")
|
||||||
|
.where(conditions)
|
||||||
|
.andWhere(
|
||||||
|
_data.root != undefined && _data.root != null
|
||||||
|
? _data.root[0] != null
|
||||||
|
? `posMaster.orgRootId IN (:...root)`
|
||||||
|
: `posMaster.orgRootId is null`
|
||||||
|
: "1=1",
|
||||||
{
|
{
|
||||||
...checkChildConditions,
|
root: _data.root,
|
||||||
...typeCondition,
|
|
||||||
...revisionCondition,
|
|
||||||
...(body.keyword &&
|
|
||||||
(masterId.length > 0
|
|
||||||
? { id: In(masterId) }
|
|
||||||
: { posMasterNo: Like(`%${body.keyword}%`) })),
|
|
||||||
},
|
},
|
||||||
];
|
)
|
||||||
|
.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(
|
||||||
|
_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,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.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();
|
||||||
|
|
||||||
let [posMaster, total] = await AppDataSource.getRepository(PosMaster)
|
//แก้ค้นหา
|
||||||
.createQueryBuilder("posMaster")
|
let _position: any[] = [];
|
||||||
.leftJoinAndSelect("posMaster.orgRoot", "orgRoot")
|
let x: any = null;
|
||||||
.leftJoinAndSelect("posMaster.orgChild1", "orgChild1")
|
let y: any = null;
|
||||||
.leftJoinAndSelect("posMaster.orgChild2", "orgChild2")
|
if (body.keyword != null && body.keyword != "") {
|
||||||
.leftJoinAndSelect("posMaster.orgChild3", "orgChild3")
|
const position = await this.positionRepository.find({
|
||||||
.leftJoinAndSelect("posMaster.orgChild4", "orgChild4")
|
relations: ["posType", "posLevel", "posExecutive"],
|
||||||
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
|
where: { posMasterId: In(posMaster.map((x) => x.id)) },
|
||||||
.leftJoinAndSelect("posMaster.next_holder", "next_holder")
|
order: { createdAt: "ASC" },
|
||||||
.leftJoinAndSelect("posMaster.orgRevision", "orgRevision")
|
});
|
||||||
.where(conditions)
|
for (let data of position) {
|
||||||
.andWhere(
|
x = data.posMasterId;
|
||||||
_data.root != undefined && _data.root != null
|
if (y != x) {
|
||||||
? _data.root[0] != null
|
if (
|
||||||
? `posMaster.orgRootId IN (:...root)`
|
data.positionName.includes(body.keyword) ||
|
||||||
: `posMaster.orgRootId is null`
|
data.posType.posTypeName.includes(body.keyword) ||
|
||||||
: "1=1",
|
data.posLevel.posLevelName.includes(body.keyword)
|
||||||
{
|
) {
|
||||||
root: _data.root,
|
_position.push(data);
|
||||||
},
|
|
||||||
)
|
|
||||||
.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(
|
|
||||||
_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,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.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();
|
|
||||||
|
|
||||||
//แก้ค้นหา
|
|
||||||
let _position: any[] = [];
|
|
||||||
let x: any = null;
|
|
||||||
let y: any = null;
|
|
||||||
if (body.keyword != null && body.keyword != ""){
|
|
||||||
const position = await this.positionRepository.find({
|
|
||||||
relations: ["posType", "posLevel", "posExecutive"],
|
|
||||||
where: { posMasterId: In(posMaster.map(x => x.id))},
|
|
||||||
order: { createdAt: "ASC" }
|
|
||||||
});
|
|
||||||
for(let data of position){
|
|
||||||
x = data.posMasterId
|
|
||||||
if(y != x){
|
|
||||||
if(
|
|
||||||
data.positionName.includes(body.keyword) ||
|
|
||||||
data.posType.posTypeName.includes(body.keyword) ||
|
|
||||||
data.posLevel.posLevelName.includes(body.keyword)
|
|
||||||
){
|
|
||||||
_position.push(data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
y = x;
|
|
||||||
}
|
}
|
||||||
|
y = x;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(_position.length > 0){
|
if (_position.length > 0) {
|
||||||
posMaster = posMaster.filter((x) => _position.some(y => y.posMasterId === x.id));
|
posMaster = posMaster.filter((x) => _position.some((y) => y.posMasterId === x.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const formattedData = await Promise.all(
|
const formattedData = await Promise.all(
|
||||||
posMaster.map(async (posMaster) => {
|
posMaster.map(async (posMaster) => {
|
||||||
|
|
@ -3312,10 +3311,10 @@ export class PositionController extends Controller {
|
||||||
.getManyAndCount();
|
.getManyAndCount();
|
||||||
|
|
||||||
const _posType = await this.posTypeRepository.find({
|
const _posType = await this.posTypeRepository.find({
|
||||||
where: { posTypeName: In(["ทั่วไป", "วิชาการ"]) }
|
where: { posTypeName: In(["ทั่วไป", "วิชาการ"]) },
|
||||||
});
|
});
|
||||||
const _posLevel = await this.posLevelRepository.find({
|
const _posLevel = await this.posLevelRepository.find({
|
||||||
where: { posLevelName: In(["ปฏิบัติงาน", "ปฏิบัติการ"]) }
|
where: { posLevelName: In(["ปฏิบัติงาน", "ปฏิบัติการ"]) },
|
||||||
});
|
});
|
||||||
|
|
||||||
const formattedData = await Promise.all(
|
const formattedData = await Promise.all(
|
||||||
|
|
@ -3382,12 +3381,13 @@ export class PositionController extends Controller {
|
||||||
nodeId = posMaster.orgRootId;
|
nodeId = posMaster.orgRootId;
|
||||||
}
|
}
|
||||||
|
|
||||||
let _position: any
|
let _position: any;
|
||||||
if( posLevel == null && posType == null && body.position != null) {
|
if (posLevel == null && posType == null && body.position != null) {
|
||||||
_position = posMaster.positions
|
_position = posMaster.positions
|
||||||
.filter((x:any) =>
|
.filter(
|
||||||
_posType.some((y:any) => y.id == x.posTypeId) &&
|
(x: any) =>
|
||||||
_posLevel.some((z:any) => z.id == x.posLevelId)
|
_posType.some((y: any) => y.id == x.posTypeId) &&
|
||||||
|
_posLevel.some((z: any) => z.id == x.posLevelId),
|
||||||
)
|
)
|
||||||
.map((position) => ({
|
.map((position) => ({
|
||||||
id: position.id,
|
id: position.id,
|
||||||
|
|
@ -3405,8 +3405,7 @@ export class PositionController extends Controller {
|
||||||
positionIsSelected: position.positionIsSelected,
|
positionIsSelected: position.positionIsSelected,
|
||||||
isSpecial: position.isSpecial,
|
isSpecial: position.isSpecial,
|
||||||
}));
|
}));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
_position = posMaster.positions.map((position) => ({
|
_position = posMaster.positions.map((position) => ({
|
||||||
id: position.id,
|
id: position.id,
|
||||||
positionName: position.positionName,
|
positionName: position.positionName,
|
||||||
|
|
@ -4594,7 +4593,7 @@ export class PositionController extends Controller {
|
||||||
.leftJoinAndSelect("posMaster.orgChild4", "orgChild4")
|
.leftJoinAndSelect("posMaster.orgChild4", "orgChild4")
|
||||||
.where(conditions)
|
.where(conditions)
|
||||||
.andWhere({
|
.andWhere({
|
||||||
current_holderId: Not(IsNull()),
|
current_holderId: IsNull(),
|
||||||
})
|
})
|
||||||
.andWhere(
|
.andWhere(
|
||||||
_data.root != undefined && _data.root != null
|
_data.root != undefined && _data.root != null
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue