feat: isAllRoot
This commit is contained in:
parent
7694a83d5a
commit
cfd5ced28a
2 changed files with 124 additions and 102 deletions
|
|
@ -17,10 +17,13 @@ import HttpStatusCode from "../interfaces/http-status";
|
|||
import HttpError from "../interfaces/http-error";
|
||||
import { PosMasterAct } from "../entities/PosMasterAct";
|
||||
import { PosMaster } from "../entities/PosMaster";
|
||||
import { Brackets, LessThan, MoreThan } from "typeorm";
|
||||
import { Brackets, In, IsNull, LessThan, MoreThan, Not } from "typeorm";
|
||||
import permission from "../interfaces/permission";
|
||||
import { OrgRevision } from "../entities/OrgRevision";
|
||||
import Extension from "../interfaces/extension";
|
||||
import { ProfileActposition } from "../entities/ProfileActposition";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { escape } from "querystring";
|
||||
|
||||
@Route("api/v1/org/pos/act")
|
||||
@Tags("PosMasterAct")
|
||||
|
|
@ -89,6 +92,120 @@ export class PosMasterActController extends Controller {
|
|||
return new HttpSuccess(posMasterAct);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* API ค้นหาตำแหน่งในระบบสมัครสอบ ขรก.
|
||||
*
|
||||
* @summary ค้นหาตำแหน่งในระบบสมัครสอบ ขรก.
|
||||
*
|
||||
*/
|
||||
@Post("search")
|
||||
async searchAct(
|
||||
@Request() request: RequestWithUser,
|
||||
@Body()
|
||||
body: {
|
||||
posmasterId: string;
|
||||
isAll: boolean;
|
||||
isAllRoot?: boolean;
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
},
|
||||
) {
|
||||
await new permission().PermissionGet(request, "SYS_ACTING");
|
||||
const {
|
||||
page = 1,
|
||||
pageSize = 100,
|
||||
} = body
|
||||
const posMasterMain = await this.posMasterRepository.findOne({
|
||||
where: { id: body.posmasterId },
|
||||
relations: ["posMasterActs"],
|
||||
});
|
||||
if (posMasterMain == null) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
|
||||
}
|
||||
let posId: any = posMasterMain.posMasterActs.map((x) => x.posMasterChildId);
|
||||
posId.push(body.posmasterId);
|
||||
let typeCondition: any = {};
|
||||
if (!body.isAllRoot) {
|
||||
if (body.isAll == true) {
|
||||
typeCondition = {
|
||||
orgRootId: posMasterMain.orgRootId,
|
||||
orgChild1Id: posMasterMain.orgChild1Id,
|
||||
orgChild2Id: posMasterMain.orgChild2Id,
|
||||
orgChild3Id: posMasterMain.orgChild3Id,
|
||||
orgChild4Id: posMasterMain.orgChild4Id,
|
||||
current_holderId: Not(IsNull()),
|
||||
id: Not(In(posId)),
|
||||
};
|
||||
} else {
|
||||
typeCondition = {
|
||||
orgRootId: posMasterMain.orgRootId == null ? IsNull() : posMasterMain.orgRootId,
|
||||
orgChild1Id: posMasterMain.orgChild1Id == null ? IsNull() : posMasterMain.orgChild1Id,
|
||||
orgChild2Id: posMasterMain.orgChild2Id == null ? IsNull() : posMasterMain.orgChild2Id,
|
||||
orgChild3Id: posMasterMain.orgChild3Id == null ? IsNull() : posMasterMain.orgChild3Id,
|
||||
orgChild4Id: posMasterMain.orgChild4Id == null ? IsNull() : posMasterMain.orgChild4Id,
|
||||
current_holderId: Not(IsNull()),
|
||||
id: Not(In(posId)),
|
||||
};
|
||||
}
|
||||
} else {
|
||||
typeCondition = {
|
||||
orgRootId: posMasterMain.orgRootId,
|
||||
current_holderId: Not(IsNull()),
|
||||
id: Not(In(posId)),
|
||||
};
|
||||
}
|
||||
|
||||
const [posMaster, total] = await this.posMasterRepository.findAndCount({
|
||||
where: typeCondition,
|
||||
relations: [
|
||||
"orgRoot",
|
||||
"orgChild1",
|
||||
"orgChild2",
|
||||
"orgChild3",
|
||||
"orgChild4",
|
||||
"current_holder",
|
||||
"current_holder.posLevel",
|
||||
"current_holder.posType",
|
||||
],
|
||||
skip: (page - 1) * pageSize,
|
||||
take: pageSize,
|
||||
});
|
||||
|
||||
const data = await Promise.all(
|
||||
posMaster
|
||||
.sort((a, b) => a.posMasterOrder - b.posMasterOrder)
|
||||
.map((item) => {
|
||||
const shortName =
|
||||
item.orgChild4 != null
|
||||
? `${item.orgChild4.orgChild4ShortName} ${item.posMasterNo}`
|
||||
: item?.orgChild3 != null
|
||||
? `${item.orgChild3.orgChild3ShortName} ${item.posMasterNo}`
|
||||
: item?.orgChild2 != null
|
||||
? `${item.orgChild2.orgChild2ShortName} ${item.posMasterNo}`
|
||||
: item?.orgChild1 != null
|
||||
? `${item.orgChild1.orgChild1ShortName} ${item.posMasterNo}`
|
||||
: item?.orgRoot != null
|
||||
? `${item.orgRoot.orgRootShortName} ${item.posMasterNo}`
|
||||
: null;
|
||||
return {
|
||||
id: item.id,
|
||||
citizenId: item.current_holder?.citizenId ?? null,
|
||||
isDirector: item.isDirector ?? null,
|
||||
prefix: item.current_holder?.prefix ?? null,
|
||||
firstName: item.current_holder?.firstName ?? null,
|
||||
lastName: item.current_holder?.lastName ?? null,
|
||||
posLevel: item.current_holder?.posLevel?.posLevelName ?? null,
|
||||
posType: item.current_holder?.posType?.posTypeName ?? null,
|
||||
position: item.current_holder?.position ?? null,
|
||||
posNo: shortName,
|
||||
};
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess({ data: data, total });
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* API ลบรักษาการในตำแหน่ง
|
||||
*
|
||||
|
|
@ -498,12 +615,12 @@ export class PosMasterActController extends Controller {
|
|||
x.posMasterChild?.orgRoot?.orgRootShortName,
|
||||
].find((name) => !!name) && x.posMasterChild?.posMasterNo
|
||||
? `${[
|
||||
x.posMasterChild?.orgChild4?.orgChild4ShortName,
|
||||
x.posMasterChild?.orgChild3?.orgChild3ShortName,
|
||||
x.posMasterChild?.orgChild2?.orgChild2ShortName,
|
||||
x.posMasterChild?.orgChild1?.orgChild1ShortName,
|
||||
x.posMasterChild?.orgRoot?.orgRootShortName,
|
||||
].find((name) => !!name)} ${x.posMasterChild.posMasterNo}`
|
||||
x.posMasterChild?.orgChild4?.orgChild4ShortName,
|
||||
x.posMasterChild?.orgChild3?.orgChild3ShortName,
|
||||
x.posMasterChild?.orgChild2?.orgChild2ShortName,
|
||||
x.posMasterChild?.orgChild1?.orgChild1ShortName,
|
||||
x.posMasterChild?.orgRoot?.orgRootShortName,
|
||||
].find((name) => !!name)} ${x.posMasterChild.posMasterNo}`
|
||||
: x.posMasterChild?.posMasterNo || null;
|
||||
const orgShortNameAct =
|
||||
[
|
||||
|
|
|
|||
|
|
@ -4943,101 +4943,6 @@ export class PositionController extends Controller {
|
|||
return new HttpSuccess({ data: formattedData, total });
|
||||
}
|
||||
|
||||
/**
|
||||
* API ค้นหาตำแหน่งในระบบสมัครสอบ ขรก.
|
||||
*
|
||||
* @summary ค้นหาตำแหน่งในระบบสมัครสอบ ขรก.
|
||||
*
|
||||
*/
|
||||
@Post("act/search")
|
||||
async searchAct(
|
||||
@Request() request: RequestWithUser,
|
||||
@Body()
|
||||
body: {
|
||||
posmasterId: string;
|
||||
isAll: boolean;
|
||||
},
|
||||
) {
|
||||
await new permission().PermissionGet(request, "SYS_ACTING");
|
||||
const posMasterMain = await this.posMasterRepository.findOne({
|
||||
where: { id: body.posmasterId },
|
||||
relations: ["posMasterActs"],
|
||||
});
|
||||
if (posMasterMain == null) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่งนี้");
|
||||
}
|
||||
let posId: any = posMasterMain.posMasterActs.map((x) => x.posMasterChildId);
|
||||
posId.push(body.posmasterId);
|
||||
let typeCondition: any = {};
|
||||
if (body.isAll == true) {
|
||||
typeCondition = {
|
||||
orgRootId: posMasterMain.orgRootId,
|
||||
orgChild1Id: posMasterMain.orgChild1Id,
|
||||
orgChild2Id: posMasterMain.orgChild2Id,
|
||||
orgChild3Id: posMasterMain.orgChild3Id,
|
||||
orgChild4Id: posMasterMain.orgChild4Id,
|
||||
current_holderId: Not(IsNull()),
|
||||
id: Not(In(posId)),
|
||||
};
|
||||
} else {
|
||||
typeCondition = {
|
||||
orgRootId: posMasterMain.orgRootId == null ? IsNull() : posMasterMain.orgRootId,
|
||||
orgChild1Id: posMasterMain.orgChild1Id == null ? IsNull() : posMasterMain.orgChild1Id,
|
||||
orgChild2Id: posMasterMain.orgChild2Id == null ? IsNull() : posMasterMain.orgChild2Id,
|
||||
orgChild3Id: posMasterMain.orgChild3Id == null ? IsNull() : posMasterMain.orgChild3Id,
|
||||
orgChild4Id: posMasterMain.orgChild4Id == null ? IsNull() : posMasterMain.orgChild4Id,
|
||||
current_holderId: Not(IsNull()),
|
||||
id: Not(In(posId)),
|
||||
};
|
||||
}
|
||||
|
||||
const posMaster = await this.posMasterRepository.find({
|
||||
where: typeCondition,
|
||||
relations: [
|
||||
"orgRoot",
|
||||
"orgChild1",
|
||||
"orgChild2",
|
||||
"orgChild3",
|
||||
"orgChild4",
|
||||
"current_holder",
|
||||
"current_holder.posLevel",
|
||||
"current_holder.posType",
|
||||
],
|
||||
});
|
||||
|
||||
const data = await Promise.all(
|
||||
posMaster
|
||||
.sort((a, b) => a.posMasterOrder - b.posMasterOrder)
|
||||
.map((item) => {
|
||||
const shortName =
|
||||
item.orgChild4 != null
|
||||
? `${item.orgChild4.orgChild4ShortName} ${item.posMasterNo}`
|
||||
: item?.orgChild3 != null
|
||||
? `${item.orgChild3.orgChild3ShortName} ${item.posMasterNo}`
|
||||
: item?.orgChild2 != null
|
||||
? `${item.orgChild2.orgChild2ShortName} ${item.posMasterNo}`
|
||||
: item?.orgChild1 != null
|
||||
? `${item.orgChild1.orgChild1ShortName} ${item.posMasterNo}`
|
||||
: item?.orgRoot != null
|
||||
? `${item.orgRoot.orgRootShortName} ${item.posMasterNo}`
|
||||
: null;
|
||||
return {
|
||||
id: item.id,
|
||||
citizenId: item.current_holder?.citizenId ?? null,
|
||||
isDirector: item.isDirector ?? null,
|
||||
prefix: item.current_holder?.prefix ?? null,
|
||||
firstName: item.current_holder?.firstName ?? null,
|
||||
lastName: item.current_holder?.lastName ?? null,
|
||||
posLevel: item.current_holder?.posLevel?.posLevelName ?? null,
|
||||
posType: item.current_holder?.posType?.posTypeName ?? null,
|
||||
position: item.current_holder?.position ?? null,
|
||||
posNo: shortName,
|
||||
};
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* API บันทึกตำแหน่งใหม่
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue