แก้ข้อความ/ตัดข้อมูลรายงาน ทปอ.สามัญ #2274

This commit is contained in:
harid 2026-03-20 11:02:53 +07:00
parent 66d8ba089d
commit bc83a2bc40
3 changed files with 517 additions and 141 deletions

View file

@ -1,6 +1,17 @@
import { AppDataSource } from "../database/data-source";
import { CommandRecive } from "../entities/CommandRecive";
import { Command } from "../entities/Command";
import { OrgRoot } from "../entities/OrgRoot";
import { Profile } from "../entities/Profile";
export interface PosNumCodeSitResult {
posNumCodeSit: string;
posNumCodeSitAbb: string;
commandTypeName: string;
commandNo: string;
commandYear: number;
commandExcecuteDate: Date;
}
/**
*
@ -44,3 +55,92 @@ export async function reOrderCommandRecivesAndDelete(
}
}
/**
* posNumCodeSit posNumCodeSitAbb commandId
* @param commandId ID
* @param status ()
* @returns Promise<PosNumCodeSitResult>
*/
export async function getPosNumCodeSit(
commandId: string,
status?: string
): Promise<PosNumCodeSitResult> {
const commandRepo = AppDataSource.getRepository(Command);
const orgRootRepo = AppDataSource.getRepository(OrgRoot);
const profileRepo = AppDataSource.getRepository(Profile);
let posNumCodeSit:string = "";
let posNumCodeSitAbb:string = "";
let commandTypeName:string = "";
let commandNo:string = "";
let commandYear:number = 0;
let commandExcecuteDate:Date = new Date;
let _command: Command | null;
if (!status) {
_command = await commandRepo.findOne({
where: { id: commandId },
relations: { commandType: true }
});
}
else {
_command = await commandRepo.findOne({
where: { id: commandId, status: status },
relations: { commandType: true }
});
}
if (_command) {
if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") {
const orgRootDeputy = await orgRootRepo.findOne({
where: {
isDeputy: true,
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
},
relations: ["orgRevision"],
});
posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร";
posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป.";
} else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") {
posNumCodeSit = "กรุงเทพมหานคร";
posNumCodeSitAbb = "กทม.";
} else {
let _profileAdmin = await profileRepo.findOne({
where: {
keycloak: _command?.createdUserId.toString(),
current_holders: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
},
},
relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"],
});
posNumCodeSit =
_profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootName)?.orgRoot.orgRootName ??
"";
posNumCodeSitAbb =
_profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootShortName)?.orgRoot
.orgRootShortName ?? "";
}
commandTypeName = _command?.commandType?.name ?? "";
commandNo = _command?.commandNo ?? "";
commandYear = _command?.commandYear;
commandExcecuteDate = _command?.commandExcecuteDate;
}
return {
posNumCodeSit,
posNumCodeSitAbb,
commandTypeName,
commandNo,
commandYear,
commandExcecuteDate,
};
}