ออกคำสั่ง
This commit is contained in:
parent
63ed0534d0
commit
3f3ec27abd
8 changed files with 268 additions and 19 deletions
|
|
@ -17,7 +17,7 @@ import HttpStatusCode from "../interfaces/http-status";
|
|||
import HttpError from "../interfaces/http-error";
|
||||
import { PosMasterAct } from "../entities/PosMasterAct";
|
||||
import { PosMaster } from "../entities/PosMaster";
|
||||
import { LessThan, MoreThan } from "typeorm";
|
||||
import { Brackets, LessThan, MoreThan } from "typeorm";
|
||||
import { OrgRevision } from "../entities/OrgRevision";
|
||||
import Extension from "../interfaces/extension";
|
||||
|
||||
|
|
@ -390,4 +390,116 @@ export class PosMasterActController extends Controller {
|
|||
);
|
||||
return new HttpSuccess(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายชื่อตามกลุ่มในรักษาการแทน
|
||||
*
|
||||
* @summary รายชื่อตามกลุ่มในรักษาการแทน
|
||||
*
|
||||
*/
|
||||
@Post("report/draft")
|
||||
async reportDraft(
|
||||
@Body()
|
||||
body: {
|
||||
type: string;
|
||||
rootId: string;
|
||||
},
|
||||
) {
|
||||
let conditionGroup = "";
|
||||
if (body.type.trim().toUpperCase() == "GROUP1.1") {
|
||||
conditionGroup =
|
||||
"(posType.posTypeName = 'ทั่วไป' AND posLevel.posLevelName = 'ชำนาญงาน') OR (posType.posTypeName = 'ทั่วไป' AND posLevel.posLevelName = 'ปฏิบัติงาน') OR (posType.posTypeName = 'วิชาการ' AND posLevel.posLevelName = 'ปฏิบัติการ') OR (posType.posTypeName = 'วิชาการ' AND posLevel.posLevelName = 'ชำนาญการ')";
|
||||
} else if (body.type.trim().toUpperCase() == "GROUP1.2") {
|
||||
conditionGroup =
|
||||
"(posType.posTypeName = 'ทั่วไป' AND posLevel.posLevelName = 'อาวุโส') OR (posType.posTypeName = 'วิชาการ' AND posLevel.posLevelName = 'ชำนาญการพิเศษ') OR (posType.posTypeName = 'อำนวยการ' AND posLevel.posLevelName = 'ต้น')";
|
||||
} else if (body.type.trim().toUpperCase() == "GROUP2") {
|
||||
conditionGroup =
|
||||
"(posType.posTypeName = 'ทั่วไป' AND posLevel.posLevelName = 'ทักษะพิเศษ') OR (posType.posTypeName = 'วิชาการ' AND posLevel.posLevelName = 'เชี่ยวชาญ') OR (posType.posTypeName = 'วิชาการ' AND posLevel.posLevelName = 'ทรงคุณวุฒิ') OR (posType.posTypeName = 'อำนวยการ' AND posLevel.posLevelName = 'สูง') OR (posType.posTypeName = 'บริหาร' AND posLevel.posLevelName = 'ต้น') OR (posType.posTypeName = 'บริหาร' AND posLevel.posLevelName = 'สูง')";
|
||||
} else {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "กลุ่มเป้าหมายไม่ถูกต้อง");
|
||||
}
|
||||
|
||||
let posMaster = await AppDataSource.getRepository(PosMasterAct)
|
||||
.createQueryBuilder("posMasterAct")
|
||||
.leftJoinAndSelect("posMasterAct.posMasterChild", "posMasterChild")
|
||||
.leftJoinAndSelect("posMasterChild.orgRoot", "orgRoot")
|
||||
.leftJoinAndSelect("posMasterChild.orgChild1", "orgChild1")
|
||||
.leftJoinAndSelect("posMasterChild.orgChild2", "orgChild2")
|
||||
.leftJoinAndSelect("posMasterChild.orgChild3", "orgChild3")
|
||||
.leftJoinAndSelect("posMasterChild.orgChild4", "orgChild4")
|
||||
.leftJoinAndSelect("posMasterChild.current_holder", "current_holder")
|
||||
.leftJoinAndSelect("posMasterChild.positions", "positions")
|
||||
.leftJoinAndSelect("positions.posType", "posType")
|
||||
.leftJoinAndSelect("positions.posLevel", "posLevel")
|
||||
.leftJoinAndSelect("posMasterChild.orgRevision", "orgRevision")
|
||||
.andWhere("posMasterChild.orgRootId LIKE :orgRootId", {
|
||||
orgRootId: body.type.trim().toUpperCase() == "GROUP1.1" ? body.rootId : `%%`,
|
||||
})
|
||||
.andWhere("posMasterAct.statusReport = :statusReport", { statusReport: "PENDING" })
|
||||
.andWhere("posMasterChild.current_holderId IS NOT NULL")
|
||||
.andWhere("orgRevision.orgRevisionIsCurrent = :orgRevisionIsCurrent", {
|
||||
orgRevisionIsCurrent: true,
|
||||
})
|
||||
.andWhere("orgRevision.orgRevisionIsDraft = :orgRevisionIsDraft", {
|
||||
orgRevisionIsDraft: false,
|
||||
})
|
||||
.andWhere("positions.positionIsSelected = :isSelected", { isSelected: true })
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.andWhere(conditionGroup);
|
||||
}),
|
||||
)
|
||||
.orderBy("posMasterChild.posMasterOrder", "ASC")
|
||||
.select([
|
||||
"posMasterAct.id",
|
||||
"posMasterChild.posMasterNo",
|
||||
"positions.positionName",
|
||||
"positions.positionIsSelected",
|
||||
"posType.posTypeName",
|
||||
"posLevel.posLevelName",
|
||||
"orgRoot.orgRootShortName",
|
||||
"orgChild1.orgChild1ShortName",
|
||||
"orgChild2.orgChild2ShortName",
|
||||
"orgChild3.orgChild3ShortName",
|
||||
"orgChild4.orgChild4ShortName",
|
||||
"current_holder.prefix",
|
||||
"current_holder.firstName",
|
||||
"current_holder.lastName",
|
||||
"current_holder.id",
|
||||
"current_holder.citizenId",
|
||||
])
|
||||
.getMany();
|
||||
const _posMaster = posMaster.map((x) => {
|
||||
const posMasterNo =
|
||||
x.posMasterChild.orgChild4 != null
|
||||
? `${x.posMasterChild.orgChild4.orgChild4ShortName}${x.posMasterChild.posMasterNo}`
|
||||
: x.posMasterChild != null && x?.posMasterChild?.orgChild3 != null
|
||||
? `${x.posMasterChild.orgChild3.orgChild3ShortName}${x.posMasterChild.posMasterNo}`
|
||||
: x.posMasterChild != null && x?.posMasterChild?.orgChild2 != null
|
||||
? `${x.posMasterChild.orgChild2.orgChild2ShortName}${x.posMasterChild.posMasterNo}`
|
||||
: x.posMasterChild != null && x?.posMasterChild?.orgChild1 != null
|
||||
? `${x.posMasterChild.orgChild1.orgChild1ShortName}${x.posMasterChild.posMasterNo}`
|
||||
: x.posMasterChild != null && x?.posMasterChild?.orgRoot != null
|
||||
? `${x.posMasterChild.orgRoot.orgRootShortName}${x.posMasterChild.posMasterNo}`
|
||||
: null;
|
||||
const position =
|
||||
x.posMasterChild.positions.filter((x) => x.positionIsSelected == true).length > 0
|
||||
? x.posMasterChild.positions.filter((x) => x.positionIsSelected == true)[0]
|
||||
: null;
|
||||
return {
|
||||
id: x.id,
|
||||
posMasterNo: posMasterNo,
|
||||
positionName: position?.positionName || null,
|
||||
posType: position?.posType?.posTypeName || null,
|
||||
posLevel: position?.posLevel?.posLevelName || null,
|
||||
profileId: x.posMasterChild?.current_holder?.id || null,
|
||||
prefix: x.posMasterChild?.current_holder?.prefix || null,
|
||||
firstName: x.posMasterChild?.current_holder?.firstName || null,
|
||||
lastName: x.posMasterChild?.current_holder?.lastName || null,
|
||||
citizenId: x.posMasterChild?.current_holder?.citizenId || null,
|
||||
};
|
||||
});
|
||||
|
||||
return new HttpSuccess(_posMaster);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue