fix แสดงกรณีรักษาการแทนผิด #2472
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m0s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m0s
This commit is contained in:
parent
760fef5c2f
commit
60191a23d7
3 changed files with 144 additions and 8 deletions
|
|
@ -89,7 +89,7 @@ import { ProfileAssistance } from "../entities/ProfileAssistance";
|
||||||
import { CommandRecive } from "../entities/CommandRecive";
|
import { CommandRecive } from "../entities/CommandRecive";
|
||||||
import { CommandCode } from "../entities/CommandCode";
|
import { CommandCode } from "../entities/CommandCode";
|
||||||
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
||||||
import { CreatePosMasterHistoryOfficer, getTopDegrees } from "../services/PositionService";
|
import { CreatePosMasterHistoryOfficer, getTopDegrees, getPosMasterPositions } from "../services/PositionService";
|
||||||
import { ProfileLeaveService } from "../services/ProfileLeaveService";
|
import { ProfileLeaveService } from "../services/ProfileLeaveService";
|
||||||
// import { PostRetireToExprofile } from "./ExRetirementController";
|
// import { PostRetireToExprofile } from "./ExRetirementController";
|
||||||
import { getPosNumCodeSit } from "../services/CommandService";
|
import { getPosNumCodeSit } from "../services/CommandService";
|
||||||
|
|
@ -3433,7 +3433,44 @@ export class ProfileController extends Controller {
|
||||||
.skip((body.page - 1) * body.pageSize)
|
.skip((body.page - 1) * body.pageSize)
|
||||||
.take(body.pageSize)
|
.take(body.pageSize)
|
||||||
.getManyAndCount();
|
.getManyAndCount();
|
||||||
return new HttpSuccess({ data: lists, total });
|
|
||||||
|
// ดึง posMasterId ทั้งหมด (36 ตัวแรกของ key) เพื่อ query positionName
|
||||||
|
const posMasterIds = lists
|
||||||
|
.map((x) => x.key?.substring(0, 36))
|
||||||
|
.filter((id) => id && id.length === 36);
|
||||||
|
const posMasterPositionMap = await getPosMasterPositions(posMasterIds);
|
||||||
|
|
||||||
|
// ปรับ positionSign สำหรับกรณีรักษาการ
|
||||||
|
const processedLists = lists.map((x: any) => {
|
||||||
|
let newPositionSign = x.positionSign;
|
||||||
|
|
||||||
|
// ตำแหน่งของคนที่เลือกไปรักษาการ
|
||||||
|
let childPosition = "";
|
||||||
|
if (x.posType === "อำนวยการ" || x.posType === "บริหาร") {
|
||||||
|
childPosition = x.posExecutiveName || "";
|
||||||
|
if (!childPosition) {
|
||||||
|
childPosition = `${x.position || ""}ระดับ${x.posLevel || ""}`.trim();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
childPosition = `${x.position || ""}${x.posLevel || ""}`.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ตำแหน่งที่รักษาการแทน
|
||||||
|
const posMasterId = x.key?.substring(0, 36);
|
||||||
|
const targetPosition = x.positionSign
|
||||||
|
? x.positionSign
|
||||||
|
: posMasterPositionMap.get(posMasterId) || "";
|
||||||
|
|
||||||
|
// สร้าง positionSign ใหม่
|
||||||
|
newPositionSign = `${childPosition} รักษาการในตำแหน่ง${targetPosition}`;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...x,
|
||||||
|
positionSign: newPositionSign,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return new HttpSuccess({ data: processedLists, total });
|
||||||
} else {
|
} else {
|
||||||
const [lists, total] = await AppDataSource.getRepository(viewDirector)
|
const [lists, total] = await AppDataSource.getRepository(viewDirector)
|
||||||
.createQueryBuilder("viewDirector")
|
.createQueryBuilder("viewDirector")
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import { viewDirector } from "../entities/view/viewDirector";
|
||||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||||
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
||||||
import { OrgRoot } from "../entities/OrgRoot";
|
import { OrgRoot } from "../entities/OrgRoot";
|
||||||
|
import { getPosMasterPositions } from "../services/PositionService";
|
||||||
@Route("api/v1/org/workflow")
|
@Route("api/v1/org/workflow")
|
||||||
@Tags("Workflow")
|
@Tags("Workflow")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
|
|
@ -1071,12 +1072,49 @@ export class WorkflowController extends Controller {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// 8. ปรับ response mapping (ถ้าจำเป็น)
|
// 8. ปรับ response mapping (ถ้าจำเป็น)
|
||||||
const processedData = data.map((x: any) => ({
|
let posMasterPositionMap: Map<string, string> = new Map();
|
||||||
...x,
|
|
||||||
posExecutiveNameOrg:
|
if (body.isAct) {
|
||||||
(x.posExecutiveName ?? "") +
|
// ดึง posMasterId ทั้งหมด (36 ตัวแรกของ key) เพื่อ query positionName
|
||||||
(x.orgChild4 ?? x.orgChild3 ?? x.orgChild2 ?? x.orgChild1 ?? x.orgRoot ?? ""),
|
const posMasterIds = data
|
||||||
}));
|
.map((x) => x.key?.substring(0, 36))
|
||||||
|
.filter((id) => id && id.length === 36);
|
||||||
|
posMasterPositionMap = await getPosMasterPositions(posMasterIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
const processedData = data.map((x: any) => {
|
||||||
|
let newPositionSign = x.positionSign;
|
||||||
|
|
||||||
|
if (body.isAct) {
|
||||||
|
// ตำแหน่งของคนที่เลือกไปรักษาการ
|
||||||
|
let childPosition = "";
|
||||||
|
if (x.posType === "อำนวยการ" || x.posType === "บริหาร") {
|
||||||
|
childPosition = x.posExecutiveName || "";
|
||||||
|
if (!childPosition) {
|
||||||
|
childPosition = `${x.position || ""}ระดับ${x.posLevel || ""}`.trim();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
childPosition = `${x.position || ""}${x.posLevel || ""}`.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ตำแหน่งที่รักษาการแทน
|
||||||
|
const posMasterId = x.key?.substring(0, 36);
|
||||||
|
const targetPosition = x.positionSign
|
||||||
|
? x.positionSign
|
||||||
|
: posMasterPositionMap.get(posMasterId) || "";
|
||||||
|
|
||||||
|
// สร้าง positionSign ใหม่
|
||||||
|
newPositionSign = `${childPosition} รักษาการในตำแหน่ง${targetPosition}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...x,
|
||||||
|
positionSign: newPositionSign,
|
||||||
|
posExecutiveNameOrg:
|
||||||
|
(x.posExecutiveName ?? "") +
|
||||||
|
(x.orgChild4 ?? x.orgChild3 ?? x.orgChild2 ?? x.orgChild1 ?? x.orgRoot ?? ""),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
return new HttpSuccess({ data: processedData, total });
|
return new HttpSuccess({ data: processedData, total });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,67 @@ import { Position } from "../entities/Position";
|
||||||
import { ProfileEducation } from "../entities/ProfileEducation";
|
import { ProfileEducation } from "../entities/ProfileEducation";
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* function สำหรับดึงตำแหน่งที่รักษาการแทน
|
||||||
|
* ใช้กรณี positionSign ว่าง
|
||||||
|
* - ถ้า posType = "อำนวยการ" หรือ "บริหาร" ใช้ posExecutiveName
|
||||||
|
* - ถ้า posType อื่นๆ ใช้ positionName + posLevel
|
||||||
|
*/
|
||||||
|
export async function getPosMasterPositions(
|
||||||
|
posMasterIds: string[]
|
||||||
|
): Promise<Map<string, string>> {
|
||||||
|
if (posMasterIds.length === 0) {
|
||||||
|
return new Map();
|
||||||
|
}
|
||||||
|
|
||||||
|
const positionRepo = AppDataSource.getRepository(Position);
|
||||||
|
|
||||||
|
// Query รอบที่ 1: หา position ที่มีคนครอง
|
||||||
|
const positionsWithHolder = await positionRepo.find({
|
||||||
|
where: {
|
||||||
|
posMasterId: In(posMasterIds),
|
||||||
|
positionIsSelected: true,
|
||||||
|
},
|
||||||
|
relations: ["posType", "posLevel", "posExecutive"],
|
||||||
|
});
|
||||||
|
|
||||||
|
// หา posMasterId ที่ยังไม่ได้ผลลัพธ์
|
||||||
|
const foundMasterIds = new Set(positionsWithHolder.map((p) => p.posMasterId));
|
||||||
|
const missingMasterIds = posMasterIds.filter((id) => !foundMasterIds.has(id));
|
||||||
|
|
||||||
|
// Query รอบที่ 2: เฉพาะที่ขาด (กรณีไม่มีคนครอง)
|
||||||
|
let positionsWithoutHolder: Position[] = [];
|
||||||
|
if (missingMasterIds.length > 0) {
|
||||||
|
positionsWithoutHolder = await positionRepo.find({
|
||||||
|
where: {
|
||||||
|
posMasterId: In(missingMasterIds),
|
||||||
|
},
|
||||||
|
order: { createdAt: "ASC" },
|
||||||
|
relations: ["posType", "posLevel", "posExecutive"],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// รวม positions และสร้าง Map
|
||||||
|
const allPositions = [...positionsWithHolder, ...positionsWithoutHolder];
|
||||||
|
const positionMap = new Map<string, string>();
|
||||||
|
|
||||||
|
for (const pos of allPositions) {
|
||||||
|
const posTypeName = pos.posType?.posTypeName || "";
|
||||||
|
let positionText = "";
|
||||||
|
|
||||||
|
if (posTypeName === "อำนวยการ" || posTypeName === "บริหาร") {
|
||||||
|
positionText = pos.posExecutive?.posExecutiveName || `${pos.positionName || ""}ระดับ${pos.posLevel?.posLevelName || ""}`.trim();
|
||||||
|
} else {
|
||||||
|
positionText = `${pos.positionName || ""}${pos.posLevel?.posLevelName || ""}`.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
positionMap.set(pos.posMasterId, positionText);
|
||||||
|
}
|
||||||
|
|
||||||
|
return positionMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function CreatePosMasterHistoryOfficer(
|
export async function CreatePosMasterHistoryOfficer(
|
||||||
posMasterId: string,
|
posMasterId: string,
|
||||||
request: RequestWithUser | null,
|
request: RequestWithUser | null,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue