Merge branch 'develop' into adiDev

This commit is contained in:
Adisak 2026-06-12 10:01:30 +07:00
commit 1b1a234bfb
15 changed files with 197 additions and 46 deletions

View file

@ -4321,7 +4321,7 @@ export class CommandController extends Controller {
}
//ลบตำแหน่งที่รักษาการแทน
const code = _command?.commandType?.code;
if (code && ["C-PM-08", "C-PM-17", "C-PM-18"].includes(code)) {
if (code && ["C-PM-08", "C-PM-17", "C-PM-18", "C-PM-48"].includes(code)) {
removePostMasterAct(profile.id);
}
//ออกคำสั่งยกเลิกลาออก ลบเฉพาะคนที่ขอยกเลิกลาออก
@ -4733,7 +4733,7 @@ export class CommandController extends Controller {
});
// Task #2190
if (code && ["C-PM-17", "C-PM-18"].includes(code)) {
if (code && ["C-PM-17", "C-PM-18", "C-PM-48"].includes(code)) {
let organizeName = "";
if (orgRootRef) {
const names = [
@ -5594,6 +5594,7 @@ export class CommandController extends Controller {
date: item.commandDateAffect,
refCommandDate: item.commandDateSign,
refCommandNo: `${item.commandNo}/${item.commandYear}`,
refCommandId: item.commandId,
createdUserId: req.user.sub,
createdFullName: req.user.name,
lastUpdateUserId: req.user.sub,
@ -6117,6 +6118,7 @@ export class CommandController extends Controller {
date: item.commandDateAffect,
refCommandDate: item.commandDateSign,
refCommandNo: `${item.commandNo}/${item.commandYear}`,
refCommandId: item.commandId,
profileEmployeeId: item.profileId,
profileId: undefined,
});

View file

@ -8563,7 +8563,7 @@ export class OrganizationController extends Controller {
orgChild3Id,
orgChild4Id,
current_holderId: draftPos.next_holderId,
next_holderId: draftPos.next_holderId,
next_holderId: null,
isSit: draftPos.isSit,
reason: draftPos.reason,
isDirector: draftPos.isDirector,
@ -8592,6 +8592,7 @@ export class OrganizationController extends Controller {
orgChild3Id,
orgChild4Id,
current_holderId: draftPos.next_holderId,
next_holderId: null,
statusReport: "DONE",
});
@ -8984,7 +8985,16 @@ export class OrganizationController extends Controller {
// Fetch draft PosMasters with relations for history tracking
const draftPosMasters = await queryRunner.manager.find(PosMaster, {
where: { id: In(draftPosMasterIds) },
relations: ["orgRoot", "orgChild1", "orgChild2", "orgChild3", "orgChild4", "next_holder"],
relations: [
"orgRoot",
"orgChild1",
"orgChild2",
"orgChild3",
"orgChild4",
"next_holder",
"next_holder.posType",
"next_holder.posLevel",
],
});
// Fetch ALL positions for ALL posMasters in just 2 queries
@ -9122,17 +9132,22 @@ export class OrganizationController extends Controller {
org: draftPosMaster ? getOrgFullName(draftPosMaster as PosMaster) ?? _null : _null,
});
}
// ถ้าไม่ใช่ตำแหน่งนั่งทับ (isSit = false) ถึงจะอัพเดทตำแหน่งในทะเบียนประวัติ
if (nextHolderId != null && draftPos.positionIsSelected && !draftPosMaster?.isSit) {
const existing = profileUpdates.get(nextHolderId) || {};
existing.position = draftPos.positionName;
existing.posTypeId = draftPos.posTypeId;
existing.posLevelId = draftPos.posLevelId;
existing.positionField = draftPos.positionField ?? null;
existing.posExecutive = (draftPos as any).posExecutive?.posExecutiveName ?? null;
existing.positionArea = draftPos.positionArea ?? null;
existing.positionExecutiveField = draftPos.positionExecutiveField ?? null;
profileUpdates.set(nextHolderId, existing);
if (nextHolderId != null && draftPos.positionIsSelected) {
// ถ้าไม่ใช่ตำแหน่งนั่งทับ (isSit = false) ถึงจะอัพเดทตำแหน่งในทะเบียนประวัติ
if (!draftPosMaster?.isSit) {
const existing = profileUpdates.get(nextHolderId) || {};
existing.position = draftPos.positionName;
existing.posTypeId = draftPos.posTypeId;
existing.posLevelId = draftPos.posLevelId;
existing.positionField = draftPos.positionField ?? null;
existing.posExecutive = (draftPos as any).posExecutive?.posExecutiveName ?? null;
existing.positionArea = draftPos.positionArea ?? null;
existing.positionExecutiveField = draftPos.positionExecutiveField ?? null;
profileUpdates.set(nextHolderId, existing);
}
// ยังบันทึกประวัติคนครอง
if (draftPosMaster && draftPosMaster.ancestorDNA) {
// Find the selected position from draft positions
const selectedPos =
@ -9144,10 +9159,11 @@ export class OrganizationController extends Controller {
prefix: draftPosMaster.next_holder?.prefix ?? null,
firstName: draftPosMaster.next_holder?.firstName ?? null,
lastName: draftPosMaster.next_holder?.lastName ?? null,
position: selectedPos.positionName ?? null,
posType: (selectedPos as any).posType?.posTypeName ?? null,
posLevel: (selectedPos as any).posLevel?.posLevelName ?? null,
posExecutive: (selectedPos as any).posExecutive?.posExecutiveName ?? null,
// isSit = true ดึงค่าจาก profile
position: draftPosMaster?.isSit ? draftPosMaster.next_holder?.position ?? null : selectedPos.positionName ?? null,
posType: draftPosMaster?.isSit ? draftPosMaster.next_holder?.posType?.posTypeName ?? null : (selectedPos as any).posType?.posTypeName ?? null,
posLevel: draftPosMaster?.isSit ? draftPosMaster.next_holder?.posLevel?.posLevelName ?? null : (selectedPos as any).posLevel?.posLevelName ?? null,
posExecutive: draftPosMaster?.isSit ? draftPosMaster.next_holder?.posExecutive ?? null : (selectedPos as any).posExecutive?.posExecutiveName ?? null,
profileId: nextHolderId,
rootDnaId: draftPosMaster.orgRoot?.ancestorDNA ?? null,
child1DnaId: draftPosMaster.orgChild1?.ancestorDNA ?? null,

View file

@ -9153,28 +9153,41 @@ export class OrganizationDotnetController extends Controller {
}
/**
* API profileId
* @summary API profileId
* API
* @summary API
*/
@Post("check-isLeave")
@Security("internalAuth")
async findProfileIsLeave(
@Body()
req: { profileIds: string[] }
req: { citizenIds: string[] }
) {
const profile = await this.profileRepo.find({
select: { id: true },
const profiles = await this.profileRepo.find({
select: {
id: true,
citizenId: true,
isLeave: true,
isActive: true
},
where: {
id: In(req.profileIds),
isLeave: true
citizenId: In(req.citizenIds)
}
});
if (profile.length === 0) {
if (profiles.length === 0) {
return new HttpSuccess([]);
}
return new HttpSuccess(
profiles.map(p => ({
citizenId: p.citizenId,
profileId: p.id,
isLeave: p.isLeave ?? false,
isActive: p.isActive ?? false
}))
);
return new HttpSuccess(profile.map(p => p.id));
}
}

View file

@ -4242,6 +4242,7 @@ export class PositionController extends Controller {
const [posMaster, total] = await AppDataSource.getRepository(PosMaster)
.createQueryBuilder("posMaster")
.leftJoinAndSelect("posMaster.orgRevision", "orgRevision")
.leftJoinAndSelect("posMaster.orgRoot", "orgRoot")
.leftJoinAndSelect("posMaster.orgChild1", "orgChild1")
.leftJoinAndSelect("posMaster.orgChild2", "orgChild2")
@ -4253,6 +4254,8 @@ export class PositionController extends Controller {
.leftJoinAndSelect("positions.posType", "posType")
.leftJoinAndSelect("positions.posLevel", "posLevel")
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
.andWhere("orgRevision.orgRevisionIsCurrent = true")
.andWhere("orgRevision.orgRevisionIsDraft = false")
.andWhere(
new Brackets((qb) => {
qb.andWhere(typeCondition).andWhere(conditionA == null ? "1=1" : conditionA, {
@ -4431,6 +4434,7 @@ export class PositionController extends Controller {
typeCommand: string | null;
posType?: string | null;
posLevel?: string | null;
profileId?: string | null;
isAll: boolean;
isBlank: boolean;
},
@ -4472,9 +4476,13 @@ export class PositionController extends Controller {
posLevel: posLevel?.id,
};
} else if (body.typeCommand == "APPOINT") {
conditionA = "posType.posTypeRank > :posTypeRank";
// เดิม : กรองเฉพาะ posTypeRank ที่สูงกว่า
// conditionA = "posType.posTypeRank > :posTypeRank";
// ใหม่ : กรองเฉพาะ posType ที่สูงหรือต่ำกว่าก็ได้
conditionA = "positions.posTypeId != :currentPosType";
params = {
posTypeRank: posType?.posTypeRank ?? 0,
// posTypeRank: posType?.posTypeRank ?? 0,
currentPosType: posType?.id,
};
} else if (body.typeCommand == "SLIP") {
conditionA = "positions.posTypeId LIKE :posType AND posLevel.posLevelRank > :posLevelRank";
@ -4538,8 +4546,13 @@ export class PositionController extends Controller {
typeCondition.current_holderId = IsNull();
}
if (body.typeCommand === "MOVE" && body.profileId && !body.isBlank) {
typeCondition.current_holderId = Not(body.profileId);
}
const [posMaster, total] = await AppDataSource.getRepository(PosMaster)
.createQueryBuilder("posMaster")
.leftJoinAndSelect("posMaster.orgRevision", "orgRevision")
.leftJoinAndSelect("posMaster.orgRoot", "orgRoot")
.leftJoinAndSelect("posMaster.orgChild1", "orgChild1")
.leftJoinAndSelect("posMaster.orgChild2", "orgChild2")
@ -4552,6 +4565,8 @@ export class PositionController extends Controller {
.leftJoinAndSelect("positions.posLevel", "posLevel")
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
.andWhere("posMaster.next_holderId IS NULL")
.andWhere("orgRevision.orgRevisionIsCurrent = true")
.andWhere("orgRevision.orgRevisionIsDraft = false")
.andWhere(
new Brackets((qb) => {
qb.andWhere(typeCondition)

View file

@ -112,6 +112,7 @@ export class ProfileChangeNameController extends Controller {
profile.firstName = body.firstName ?? profile.firstName;
profile.lastName = body.lastName ?? profile.lastName;
profile.prefix = body.prefix ?? profile.prefix;
profile.rank = body.rank ?? profile.rank;
profile.prefixMain = profile.rank ?? profile.prefix;
await this.profileRepository.save(profile, { data: req });
setLogDataDiff(req, { before, after: profile });
@ -184,6 +185,7 @@ export class ProfileChangeNameController extends Controller {
profile.firstName = body.firstName ?? profile.firstName;
profile.lastName = body.lastName ?? profile.lastName;
profile.prefix = body.prefix ?? profile.prefix;
profile.rank = body.rank ?? profile.rank;
profile.prefixMain = profile.rank ?? profile.prefix;
await this.profileRepository.save(profile, { data: req });
setLogDataDiff(req, { before: before_profile, after: profile });

View file

@ -118,6 +118,7 @@ export class ProfileChangeNameEmployeeController extends Controller {
profile.firstName = body.firstName ?? profile.firstName;
profile.lastName = body.lastName ?? profile.lastName;
profile.prefix = body.prefix ?? profile.prefix;
profile.rank = body.rank ?? profile.rank;
profile.prefixMain = profile.rank ?? profile.prefix;
await this.profileEmployeeRepo.save(profile, { data: req });
setLogDataDiff(req, { before, after: profile });
@ -191,6 +192,7 @@ export class ProfileChangeNameEmployeeController extends Controller {
profile.firstName = body.firstName ?? profile.firstName;
profile.lastName = body.lastName ?? profile.lastName;
profile.prefix = body.prefix ?? profile.prefix;
profile.rank = body.rank ?? profile.rank;
profile.prefixMain = profile.rank ?? profile.prefix;
await this.profileEmployeeRepo.save(profile);
}

View file

@ -109,6 +109,7 @@ export class ProfileChangeNameEmployeeTempController extends Controller {
profile.firstName = body.firstName ?? profile.firstName;
profile.lastName = body.lastName ?? profile.lastName;
profile.prefix = body.prefix ?? profile.prefix;
profile.rank = body.rank ?? profile.rank;
profile.prefixMain = profile.rank ?? profile.prefix;
await this.profileEmployeeRepo.save(profile, { data: req });
setLogDataDiff(req, { before, after: profile });
@ -179,6 +180,7 @@ export class ProfileChangeNameEmployeeTempController extends Controller {
profile.firstName = body.firstName ?? profile.firstName;
profile.lastName = body.lastName ?? profile.lastName;
profile.prefix = body.prefix ?? profile.prefix;
profile.rank = body.rank ?? profile.rank;
profile.prefixMain = profile.rank ?? profile.prefix;
await this.profileEmployeeRepo.save(profile);
}