fixed#1568 แก้ไขรายการตำแหน่งติดเงื่อนไข

This commit is contained in:
Warunee Tamkoo 2026-04-24 11:38:45 +07:00
parent 8912e83227
commit 5980c140f0

View file

@ -1257,7 +1257,15 @@ export class PositionController extends Controller {
) {
await new permission().PermissionUpdate(request, "SYS_ORG");
const posMaster = await this.posMasterRepository.findOne({
relations: ["positions", "orgRevision", "orgRoot", "orgChild1", "orgChild2", "orgChild3", "orgChild4"],
relations: [
"positions",
"orgRevision",
"orgRoot",
"orgChild1",
"orgChild2",
"orgChild3",
"orgChild4",
],
where: { id: id },
});
if (!posMaster) {
@ -2403,16 +2411,16 @@ export class PositionController extends Controller {
? "posMaster.orgRootId IN (:...root)"
: "posMaster.orgRootId is null"
: "1=1",
{ root: _data.root }
{ root: _data.root },
)
.andWhere(
_data.child1 != undefined && _data.child1 != null
? _data.child1[0] != null
? "posMaster.orgChild1Id IN (:...child1)"
// : `posMaster.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}`
: `posMaster.orgChild1Id is null`
: // : `posMaster.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}`
`posMaster.orgChild1Id is null`
: "1=1",
{ child1: _data.child1 }
{ child1: _data.child1 },
)
.andWhere(
_data.child2 != undefined && _data.child2 != null
@ -2443,26 +2451,27 @@ export class PositionController extends Controller {
{
child4: _data.child4,
},
)
);
// .andWhere(checkChildConditions)
// .andWhere(typeCondition)
// .andWhere(revisionCondition);
if (body.keyword != null && body.keyword != "") {
query.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);
}),
)
query
.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(
@ -2971,50 +2980,50 @@ export class PositionController extends Controller {
const type0LastPosMasterNo =
requestBody.type == 0
? await this.posMasterRepository.find({
where: {
orgRootId: requestBody.id,
orgChild1Id: IsNull(),
},
})
where: {
orgRootId: requestBody.id,
orgChild1Id: IsNull(),
},
})
: [];
const type1LastPosMasterNo =
requestBody.type == 1
? await this.posMasterRepository.find({
where: {
orgChild1Id: requestBody.id,
orgChild2Id: IsNull(),
},
})
where: {
orgChild1Id: requestBody.id,
orgChild2Id: IsNull(),
},
})
: [];
const type2LastPosMasterNo =
requestBody.type == 2
? await this.posMasterRepository.find({
where: {
orgChild2Id: requestBody.id,
orgChild3Id: IsNull(),
},
})
where: {
orgChild2Id: requestBody.id,
orgChild3Id: IsNull(),
},
})
: [];
const type3LastPosMasterNo =
requestBody.type == 3
? await this.posMasterRepository.find({
where: {
orgChild3Id: requestBody.id,
orgChild4Id: IsNull(),
},
})
where: {
orgChild3Id: requestBody.id,
orgChild4Id: IsNull(),
},
})
: [];
const type4LastPosMasterNo =
requestBody.type == 4
? await this.posMasterRepository.find({
where: {
orgChild4Id: requestBody.id,
},
})
where: {
orgChild4Id: requestBody.id,
},
})
: [];
const allLastPosMasterNo = [
@ -3848,7 +3857,7 @@ export class PositionController extends Controller {
_profile.posMasterNo = getPosMasterNo(dataMaster);
_profile.org = getOrgFullName(dataMaster);
// ถ้าไม่ใช่ตำแหน่งนั่งทับ (isSit = false) ถึงจะอัพเดทตำแหน่งในทะเบียนประวัติ
if(!dataMaster.isSit){
if (!dataMaster.isSit) {
_profile.position = _position.positionName;
_profile.posTypeId = _position.posTypeId;
_profile.posLevelId = _position.posLevelId;
@ -5193,9 +5202,9 @@ export class PositionController extends Controller {
}
/**
* API
* API
*
* @summary ORG_070 - (ADMIN) #56
* @summary
*
*/
@Post("master/position-condition")
@ -5206,7 +5215,7 @@ export class PositionController extends Controller {
id: string;
revisionId: string;
type: number;
isAll: boolean;
isAll: boolean; // true คือเลือกเฉพาะตำแหน่งติดเงื่อนไข / false คือเลือกตำแหน่งทั้งหมด
page: number;
pageSize: number;
keyword?: string;
@ -5226,7 +5235,7 @@ export class PositionController extends Controller {
let level: any = resolveNodeLevel(orgDna);
const cannotViewRootPosMaster =
(_data.privilege === "PARENT") ||
_data.privilege === "PARENT" ||
(_data.privilege === "BROTHER" && level > 1) ||
(_data.privilege === "CHILD" && level > 0) ||
(_data.privilege === "NORMAL" && level != 0);
@ -5258,46 +5267,46 @@ export class PositionController extends Controller {
typeCondition = {
...(cannotViewRootPosMaster ? { orgRootId: null } : { orgRootId: body.id }),
};
if (!body.isAll) {
checkChildConditions = {
orgChild1Id: IsNull(),
};
searchShortName = `CONCAT(orgRoot.orgRootShortName," ",COALESCE(posMaster.posMasterNoPrefix, ""),posMaster.posMasterNo,COALESCE(posMaster.posMasterNoSuffix, "")) like '%${body.keyword}%'`;
} else {
}
// if (!body.isAll) {
// checkChildConditions = {
// orgChild1Id: IsNull(),
// };
// searchShortName = `CONCAT(orgRoot.orgRootShortName," ",COALESCE(posMaster.posMasterNoPrefix, ""),posMaster.posMasterNo,COALESCE(posMaster.posMasterNoSuffix, "")) like '%${body.keyword}%'`;
// } else {
// }
} else if (body.type === 1) {
typeCondition = {
...(cannotViewChild1PosMaster ? { orgChild1Id: null } : { orgChild1Id: body.id }),
};
if (!body.isAll) {
checkChildConditions = {
orgChild2Id: IsNull(),
};
searchShortName = `CONCAT(orgChild1.orgChild1ShortName," ",COALESCE(posMaster.posMasterNoPrefix, ""),posMaster.posMasterNo,COALESCE(posMaster.posMasterNoSuffix, "")) like '%${body.keyword}%'`;
} else {
}
// if (!body.isAll) {
// checkChildConditions = {
// orgChild2Id: IsNull(),
// };
// searchShortName = `CONCAT(orgChild1.orgChild1ShortName," ",COALESCE(posMaster.posMasterNoPrefix, ""),posMaster.posMasterNo,COALESCE(posMaster.posMasterNoSuffix, "")) like '%${body.keyword}%'`;
// } else {
// }
} else if (body.type === 2) {
typeCondition = {
...(cannotViewChild2PosMaster ? { orgChild2Id: null } : { orgChild2Id: body.id }),
};
if (!body.isAll) {
checkChildConditions = {
orgChild3Id: IsNull(),
};
searchShortName = `CONCAT(orgChild2.orgChild2ShortName," ",COALESCE(posMaster.posMasterNoPrefix, ""),posMaster.posMasterNo,COALESCE(posMaster.posMasterNoSuffix, "")) like '%${body.keyword}%'`;
} else {
}
// if (!body.isAll) {
// checkChildConditions = {
// orgChild3Id: IsNull(),
// };
// searchShortName = `CONCAT(orgChild2.orgChild2ShortName," ",COALESCE(posMaster.posMasterNoPrefix, ""),posMaster.posMasterNo,COALESCE(posMaster.posMasterNoSuffix, "")) like '%${body.keyword}%'`;
// } else {
// }
} else if (body.type === 3) {
typeCondition = {
...(cannotViewChild3PosMaster ? { orgChild3Id: null } : { orgChild3Id: body.id }),
};
if (!body.isAll) {
checkChildConditions = {
orgChild4Id: IsNull(),
};
searchShortName = `CONCAT(orgChild3.orgChild3ShortName," ",COALESCE(posMaster.posMasterNoPrefix, ""),posMaster.posMasterNo,COALESCE(posMaster.posMasterNoSuffix, "")) like '%${body.keyword}%'`;
} else {
}
// if (!body.isAll) {
// checkChildConditions = {
// orgChild4Id: IsNull(),
// };
// searchShortName = `CONCAT(orgChild3.orgChild3ShortName," ",COALESCE(posMaster.posMasterNoPrefix, ""),posMaster.posMasterNo,COALESCE(posMaster.posMasterNoSuffix, "")) like '%${body.keyword}%'`;
// } else {
// }
} else if (body.type === 4) {
typeCondition = {
...(cannotViewChild4PosMaster ? { orgChild4Id: null } : { orgChild4Id: body.id }),
@ -5370,7 +5379,7 @@ export class PositionController extends Controller {
(masterId.length > 0
? { id: In(masterId) }
: { posMasterNo: Like(`%${body.keyword}%`) })),
current_holderId: IsNull(),
...(!body.isAll && { isCondition: true }),
},
];
let [posMaster, total] = await AppDataSource.getRepository(PosMaster)
@ -5439,15 +5448,15 @@ export class PositionController extends Controller {
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}%'`
? `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({ current_holderId: IsNull() });
.andWhere(revisionCondition);
if (!body.isAll) {
qb.andWhere({ isCondition: true });
}
}),
)
.orWhere(
@ -5457,8 +5466,10 @@ export class PositionController extends Controller {
)
.andWhere(checkChildConditions)
.andWhere(typeCondition)
.andWhere(revisionCondition)
.andWhere({ current_holderId: IsNull() });
.andWhere(revisionCondition);
if (!body.isAll) {
qb.andWhere({ isCondition: true });
}
}),
)
.orderBy("orgRoot.orgRootOrder", "ASC")